Today it's possible to provide "data" to blocks by wrapping the block definition in a {% with %}:
{% with { "foo": "ONE"} %}
{% block one %}
foo one: {{foo}}
{% endblock %}
{% endwith %}
If the template is embedded elsewhere, and the block one overridden, it has access to the foo variable:
{% embed "something.twig" %}
{% block one %}
my foo one: {{foo}}
{% endblock %}
{% endembed %}
The output of this would be my foo one: ONE
Here's a fiddle: https://twigfiddle.com/n9e1dr
This is a neat feature. It allows you to set up variables for each block, allowing the "user" of the template (where it is embedded) to access these variables.
I wonder if the following short-hand would make sense:
{% block one with { "foo": "ONE"} %}
foo one: {{foo}}
{% endblock %}
Today it's possible to provide "data" to blocks by wrapping the block definition in a
{% with %}:If the template is embedded elsewhere, and the block
oneoverridden, it has access to thefoovariable:The output of this would be
my foo one: ONEHere's a fiddle: https://twigfiddle.com/n9e1dr
This is a neat feature. It allows you to set up variables for each block, allowing the "user" of the template (where it is embedded) to access these variables.
I wonder if the following short-hand would make sense: