B. Dionys B. Dionys - 4 years ago 268
Twig Question

Outputting HTML in twig file using Bolt CMS

I have a problem outputting html in my twig. I am using Bolt CMS 3.2

{% for item in menu %}
<li class="list-inline {{ item.path == '/#' ? 'dropdown' }}">
<a href="{{ item.path }}" >
{% autoescape %}
{% set caret = '<span class="caret"></span>' %}
{{ (item.path == '/#') ? caret|raw : item.label }}
{% endautoescape %}
</a>
</li>
{% endfor %}


But it keeps outputting the html as a string.

Answer Source

Try this :

{% autoescape false %}
   {% set caret = '<span class="caret"></span>' %}
   {{ (item.path == '/#') ? caret|raw : item.label }}
{% endautoescape %}

Source : http://twig.sensiolabs.org/doc/2.x/tags/autoescape.html

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download