The Twig include
tag lets you pull one template into another, and it allows you to pass & transform data in the process using with
in the tag like {% raw %}{% include 'file.twig' with { item: true } %}{% endraw %}
. This can be used in the embed
tag or the extends
tag as well.
This gives us the opportunity to map the data; for example:
In templates/block--system-branding-block.twig
:
{% include "@molecules/blocks/branding.twig" with {
url: path('<front>'),
text: site_name,
}
%}
In pattern-lab/source/_patterns/02-molecules/blocks/branding.twig
:
<a href="{{ url }}">
{{ text }}
</a>