Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace a string with linebreaks in Jinja2 [duplicate]

I have some data in jinja2 like this

'item1|item2|item3' 

And I want to turn it into rendered linebreaks. However, when I replace it with br/ tags, I get the br tags rendered on the page. So

{{ 'item1|item2|item3' | replace("|", "<br/>") }} 

renders as

item1<br/>item2<br/>item3<br/> 

When I want

item1 item2 item3 

on my page. I feel like I'm missing some obvious trick here...

like image 412
mcpeterson Avatar asked Dec 06 '16 22:12

mcpeterson


Video Answer


1 Answers

This has to do with autoescaping. Solution that worked for me was:

{% autoescape false %}   {{ 'item1|item2|item3' | replace("|", "<br/>") }} {% endautoescape %} 
like image 111
mcpeterson Avatar answered Oct 08 '22 09:10

mcpeterson