简体   繁体   中英

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:

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

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

Yes.

But be aware! When rendring, the variables shoud not be interpreted. You should take a look at TWIG raw filter .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM