Provide for a drillable variable structure in Twig templates

Created on 30 May 2013, almost 12 years ago
Updated 18 March 2023, about 2 years ago

Problem/Motivation

As detailed in the description for #1843798: [meta] Refactor Render API to be OO , we currently do not have a drillable, accessible way of getting to variables that a themer may anticipate being available to a parent template. This is because variables in a sub-element may be invoked by a preprocessor that runs later.

Example from a node template:

  <!-- First image, with manual tag creation -->
  {{ hide(content.field_image.0) }}
  <img class="banner" src="{{ content.field_image.0.attrs.src }}" alt="{{ content.field_image.0.attrs.alt }}" />

  <!-- Remaining content -->
  {{ content }}

  <!-- Links -->
  {{ links }}

  <!-- Comments -->
  {{ comments }}

Before the larger, long-term goals of #1843798: [meta] Refactor Render API to be OO are achieved, we'd like to get a stopgap for better drillability support in Drupal 8, at least for the Twig engine.

Proposed resolution

Provide a way for Twig to understand which variables need to be available to a template and adjust how they are prepared beforehand. Twig's compilation steps may offer us some insight into implementation.

Remaining tasks

User interface changes

None

API changes

Improved Twig syntax from what currently exists (that requires manual prep/rendering).

Related Issues

📌 Task
Status

Closed: outdated

Version

10.1

Component
Theme 

Last updated about 4 hours ago

Created by

🇺🇸United States c4rl

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024