Is it possible to use ternary operator in Twig when concatenating one string to another if some condition is true?
This works for me:
{% set a = 'initial' %} {% if foo == bar %} {% set a = a ~ ' concatenate' %} {% endif %} <p>{{ a }}</p> But when I try to simplify it like this, it throws an error:
{% set a = 'initial' ~ (foo == bar) ? ' concatenate' : '' %} <p>{{ a }}</p> Am I doing something wrong or this simplification is simply not possible in Twig?