Does twig support the execution of multiple statements within the same {%%} block?
Is it possible to use a construct like this in twig -
{%
set a = 'first'
set b = 'second'
%}
instead of this -
{% set a = 'first' %}
{% set b = 'second' %}
+3
nayak
source
to share
1 answer
You cannot execute multiple statements within a single block {% ... %}
, but the solution provided by CodeBrauer will do the trick. Anyway, keep in mind that the number of expressions to the left and right of the sign =
must be the same.
This means that if two (or three, etc.) variables have the same value, you must repeat that value. Example:
{# this will work as expected #}
{% set a, b, c = 'value', 'value', 'value' %}
{# this won't work #}
{% set a, b, c = 'value' %}
+2
Javier eguiluz
source
to share