Tuesday, October 18, 2022

[FIXED] How to display string that contains HTML in twig template?

Issue

How can I display a string that contains HTML tags in twig template?

My PHP variable contains this html and text:

$word = '<b> a word </b>';

When I do this in my twig template:

{{ word }}

I get this:

&lt;b&gt; a word &lt;b&gt;

I want this instead:

<b> a word </b>

Is it possible to get this easily?


Solution

Use raw keyword, https://twig.symfony.com/doc/3.x/api.html#escaper-extension

{{ word | raw }}


Answered By - Aurimas Ličkus
Answer Checked By - Katrina (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.