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?

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

1 Answer 1


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 }}
  • Thanks very much! It worked rightaway.
    – Ali Nouman
    Commented Feb 11, 2020 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.