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?

  • 3
    Have you tried the raw filter already? {{ node.getTitle() | replace({'|': '<br />'}) | raw }} – leymannx Feb 10 at 19:41
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 }}
  • Thanks very much! It worked rightaway. – Ali Nouman Feb 11 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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