Unescape or html decode in Twig (PHP Templating)

You can use the raw filter to make twig render raw html

http://twig.sensiolabs.org/doc/filters/raw.html

{% autoescape %}
    {{ var|raw }} {# var won't be escaped #}
{% endautoescape %}

You should be careful with using |raw. Saying that the data is safe, means you are trusting it 100%.

Personally I would suggest using a custom twig filter:

class CustomExtension extends \Twig_Extension 
{
    public function getFilters()
    {
        return array(
            new \Twig_SimpleFilter('unescape', array($this, 'unescape')),
        );
    }

    public function unescape($value)
    {
        return html_entity_decode($value);
    }
}

Add the following to your services.yml (or alternatively translate into xml).

 services:
     ha.twig.custom_extension:
     class: HA\SiteBundle\Twig\CustomExtension
     tags:
         - { name: twig.extension }

Tags:

Php

Twig