smarber smarber - 1 year ago 107
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

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

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

What's going on?

Answer Source

Try this :

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

{{ my_var|default('N/A')|raw|nl2br }}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download