Luke G Luke G - 16 days ago 5
PHP Question

TWIG variables with HTML tags

Is it possible to pass a variable that contains HTML content to a twig template, so when the page is rendered, HTML content from the variable is interpreted, instead of displayed with tags?

Example:

$this->_app->render('test.twig', [
"description" => "<b>TEST</b>"
]);


test.twig:

<li><b>Description</b><br>
{{ description }}
</li>


Result from the above example:

<b>TEST</b>


Expected result:


TEST

Answer

You can use the raw filter: http://twig.sensiolabs.org/doc/filters/raw.html

<li><b>Description</b><br>
{{ description|raw }}
</li>