smarber smarber - 3 months ago 16
Twig Question

adding the default filter apparently "disables" the filter raw

I'd like to display the raw value of a variable, if this one is empty, the default value

N/A
should be shown instead.

The code below doesn't work, but it shows even the html tags

{% set my_var = '<b>hello world!!</b>' %}
{{ my_var | default('N/A') | nl2br | raw }}


As strange as this may seem, the following code works, knowing that I just removed the
default
filter

{% set my_var = '<b>hello world!!</b>' %}
{{ my_var | nl2br | raw }}


What's going on?

DOZ DOZ
Answer

Try this :

{% set my_var = '<b>hello world!!</b>' %}

{{ my_var|default('N/A')|raw|nl2br }}
Comments