Can I use construct like this in twig -
{% 
set a = 'first' 
set b = 'second' 
%}
instead of this -
{% set a = 'first' %}
{% set b = 'second' %}
                You cannot execute several statements inside a single {% ... %} block, but the solution provided by CodeBrauer will do the trick. Anyway, keep in mind that the number of expressions on the left and on the right of the = sign must match.
This means that if the two (or three, etc.) variables share 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' %}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With