문제

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?

도움이 되었습니까?

해결책

다른 팁

You can also use:

{{ word|striptags('<b>')|raw }}

so that only <b> tag will be allowed.

{{ word|striptags('<b>,<a>,<pre>')|raw }}

if you want to allow multiple tags

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top