Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony3 + Twig : Join array with <br/>

I'm trying to display all elements inside an array and separate them with a line break, but I can't get it work.

Here is what I tried:

{{ user.roles | join('<br/>') }}
{{ user.roles | join('<br/>' | raw) }}
{{ user.roles | join('\n' | nl2br | raw) }}

Everytime I get something like:

ROLE_PARENT<br/>ROLE_ADMIN<br/>ROLE_MANAGER<br/>ROLE_USER

How can I tell twig to render <br/> as html ?

I could loop through the array but it's not the first time I tried to render html tag and I would like a definitive solution to this problem.

like image 339
Robouste Avatar asked May 05 '17 14:05

Robouste


2 Answers

A slight modification to your third attempt should do the trick as well.

{{ user.roles | join('\n')| nl2br  }}
like image 180
Dipen Shah Avatar answered Oct 18 '22 05:10

Dipen Shah


I found the error, I'm not applying the filter at the right place, this works :

{{ user.roles | join('<br/>') | raw }}
like image 31
Robouste Avatar answered Oct 18 '22 03:10

Robouste