Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 313751

Provide for a drillable variable structure in Twig templates

$
0
0

Problem/Motivation

As detailed in the description for #1843798: [meta] Refactor Render API, 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 due to that 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 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

  • Determine base use-cases
  • Determine potential implementations with respect to Twig
  • Write tests?

User interface changes

None

API changes

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


Viewing all articles
Browse latest Browse all 313751

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>