1

I want to add line breaks in title field I managed to use the replace functions in the template >

{{ node.getTitle()|replace({'|': '<br />'}) }} 

Replacement works, but outputs the field as non-HTML. Do you know about a way to force an HTML output? Or any other way to be the
a real line break instead?

1
  • 3
    Have you tried the raw filter already? {{ node.getTitle() | replace({'|': '<br />'}) | raw }} Commented Feb 10, 2020 at 19:41

1 Answer 1

4

It should help to use the raw filter, like @leymannx commented, but then your template is unsafe, because you should never use the raw filter on template variables containing user input.

So escape the node title first, then add the HTML (which you know is safe because it's hardcoded), before passing it through the raw filter:

{{ node.getTitle()|e|replace({'|': '<br />'})|raw }} 
1
  • Thanks very much! It worked rightaway. Commented Feb 11, 2020 at 12:06

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.