I'm just trying to format a haml-generated (text) mailer template, and I'm having a little difficulty getting it to read multiple line breaks. Eg: I'd have thought
Dear
= @user.name,
Your username is
= @user.username
Your status is
= @user.status
I had assumed that the multiple line breaks would be read, but the "Your status is" line comes out on the line directly beneath the username. (Yes, that many line breaks is an exaggeration of how many I want, but still)
So, the question is: Line breaks in haml text messages....erm, how?
You can also use \
or ==
:
Dear
= @user.name,
\
Your username is
= @user.username
\
\
\
\
Your status is
= @user.status
This has the added advantage of allowing you to use interpolation, whereas using the :plain
filter won't.
I'd suggest that using haml for plain text templates doesn't add anything and in most cases makes them more complex then plain old erb
templates. It's main purpose, after all, is making markup simple and omitting the need for closing tags - this doesn't apply to plain text.
If you're sending multi-mime emails, there's nothing preventing you from using html.haml
for the HTML templates and text.erb
for the plain text ones, which will preserve your multiple line breaks:
Dear <%= @user.name %>,
Your username is <%= @user.username %>
Your status is <%= @user.status %>
Try haml's :plain helper.
Dear
= @user.name,
Your username is
= @user.username
:plain
Your status is
= @user.status
*edit - you need to indent your haml text following the :plain filter as you would normally within haml.
Consider another HAML approach that is more legible.
Dear #{@user.name},
Your username is #{@user.username}
\
\
\
Your status is #{@user.status}
The filename would be something like mailer.text.haml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With