7

I am using slim as the template engine for my rails app and would like to use slim for mailer templates as well.

There is no problem with html mailer templates (views/mailer/default_email.en.html.slim) but, I am not sure how to make the text templates work.

I have placed a text template in views/mailer/default_email.en.text.slim with this content:

Hello,

Your video is ready.
= @url

Thank you,
The A-Team

But the result is parsed as slim HTML, and looks like this:

<Hello>,</Hello><Your>video is ready.</Your><Click>the link below to watch it:</Click>http://watch.thy/video<Thank>you,</Thank><The>A-Team</The>

Other than prefixing every line with a pipe, isnt there a more natural way? I even looked for an embedded plugin (like the markdown one) to say "plain text" but there is none.

Thanks in advance.

DannyB
  • 12,810
  • 5
  • 55
  • 65

2 Answers2

7

Slim was designed to generate HTML, not plain text, so you'll have to either use the pipe prefix for each line or go with .text.erb templates. I'd use the ERB templates, especially if you don't have a lot of interpolation going on.

eugen
  • 8,916
  • 11
  • 57
  • 65
  • Thank you. I was hoping I missed something and what I want to do exists. Maybe a good feature request for slim, or a plugin like the markdown one. – DannyB Jan 03 '16 at 18:26
5

For what it's worth, you can actually go the Slim route without having to prefix each line with a pipe, like so:

|
  Hello,
  <br><br>
  Your video is ready.<br>
  #{@url}
  <br><br>
  Thank you,<br>
  The A-Team

I would definitely agree with eugen though, that the text.erb route is the best fit. Just providing another solution, in case somebody absolutely insisted on doing this in Slim. :-)

jeffdill2
  • 3,968
  • 2
  • 30
  • 47
  • Actually, this is not a bad idea... I may try that. After using slim for a few days, looking at ERB hurts my eyes... Its like looking at javascript after you got used to coffeescript... – DannyB Jan 08 '16 at 17:16
  • Haha, I hear ya. When I first started using Slim (not by choice), I hated it. But now I absolutely love it. Whenever I have to jump back to Erb and raw HTML, it feels so awkward and bloated. – jeffdill2 Jan 08 '16 at 18:13