Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony yaml: keep new lines (literal)

I am trying to keep newlines in a yaml file. In a messages.en.yml file, I have.

test:|
  Here is line 1
  Here is line 2

And in form.html.twig:

{{'test'|trans}}

Both lines are rendered on the same line. Here is line 1 Here is line 2

In this link, the literal style for Yaml is explained. and in this other one, it says "Notable lacking features are: document directives, multi-line quoted messages ..."

So is it possible in Symfony Yaml to use multilines? and how?

like image 540
Baby Webmaster Avatar asked Dec 06 '25 02:12

Baby Webmaster


1 Answers

You could use |nl2br filter

{{ 'test'|trans|nl2br }}

Or, if you are sure your translation can't get altered by any user, you could use some few html in your translation.

test:|
  Here is line 1<br/>
  Here is line 2<br/>
  <br/><br/>
  Here is line 5

Then

{{ 'test'|trans|raw }}
like image 88
goto Avatar answered Dec 09 '25 00:12

goto