How to force line break in Symfony2 translation file

穿精又带淫゛_ 提交于 2019-11-30 02:03:54

问题


In my messages.en.yml I have an entry that is used for an email body which is in plaintext, so I cannot use any HTML tags. Now when I need a line break and I add a blank line after, the line break appears in my email body.

But when I try to do a line break with a non empty line following, it does not break the lines.

email:
    subject: My Subject
    message: >
        Hello %name%,

        This is my second line

        Best regards,
        John Smith
        Customer Care

Arrives like this in my mailbox

Hello Tom,

This is my second line

Best regards, John Smith Customer Care

I've tried to play around with HTML tags or with the \n which I know from PHP. But if I use <br> or <br /> in the translation file and apply the |raw filter in my twig file, the HTML tags still appear in my email body. And also if I use \n to force a line break, no line break is given and instead, the \n appear in my email as well.

Now how can I force the line break if a non empty line is following?


回答1:


Use |

email:
    subject: My Subject
    message: |
        Hello %name%,

        This is my second line

        Best regards,
        John Smith
        Customer Care



回答2:


In your translations file (e.g. messages.en.yml):

your
   translation      
      key:
         here: |
                Lorem ipsum.

                CRMPICCO.

                www.crmpicco.co.uk.

Accessing it in your Twig template:

{{ 'your.translation.key.here'|trans|nl2br }}



来源:https://stackoverflow.com/questions/20946837/how-to-force-line-break-in-symfony2-translation-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!