Display a string that contains HTML in twig templa

2019-01-10 09:00发布

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?

3条回答
三岁会撩人
2楼-- · 2019-01-10 09:38
戒情不戒烟
3楼-- · 2019-01-10 09:47

You can also use:

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

so that only <b> tag will be allowed.

查看更多
神经病院院长
4楼-- · 2019-01-10 09:48
{{ word|striptags('<b>,<a>,<pre>')|raw }}

if you want to allow multiple tags

查看更多
登录 后发表回答