Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force line break in Symfony2 translation file

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?

like image 679
Gottlieb Notschnabel Avatar asked Jan 06 '14 09:01

Gottlieb Notschnabel


2 Answers

Use |

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

        This is my second line

        Best regards,
        John Smith
        Customer Care
like image 180
xdazz Avatar answered Oct 29 '22 21:10

xdazz


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 }}

like image 15
crmpicco Avatar answered Oct 29 '22 21:10

crmpicco