symfony yaml:保留新行(文字)

symfony yaml: keep new lines (literal)

我试图在 yaml 文件中保留换行符。 在 messages.en.yml 文件中,我有。

test:|
  Here is line 1
  Here is line 2

在form.html.twig中:

{{'test'|反式}}

两行在同一行呈现。 这是第 1 行这是第 2 行

this link中解释了Yaml的字面风格。 和 in this other one,它说 "Notable lacking features are: document directives, multi-line quoted messages ..."

那么在 Symfony Yaml 中可以使用多行吗?如何?

你可以使用 |nl2br filter

{{ 'test'|trans|nl2br }}

或者,如果您确定您的翻译不会被任何用户更改,您可以在翻译中使用一些 html。

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

然后

{{ 'test'|trans|raw }}