If you are working on one template that wants to call another to prevent from dupilcating the same markup, you can call a second template from within the first. Use Twig’s template inclusion syntax, as follows:
{# The included template will have access to all the variables in the current one. #}
{# @TODO remove path to file once http://drupal.org/node/1777532 is resolved #}
{% include 'core/themes/stark/theme.inc/item_list' with { items } %}
As soon as #1777532: Extend Twig_Loader_Filesystem instance to get .twig templates paths with hierarchy for theme dependencies is resolved, we will be able to clean up our include statements to look more like the code below. But until then, please leave a the @TODO comment in your template file. You can either leave it above the include statement, or below your docblock, inside the Twig comment tags.
{# The included template will have access to all the variables in the current one. #}
{% include 'item_list' with { items } %}
Referencing template files this way will be easier for theme developers to “follow around” to get at the markup they need to change.
Comments