Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to render the email with layout? #9

Closed
rubytastic opened this issue Dec 2, 2013 · 12 comments
Closed

how to render the email with layout? #9

rubytastic opened this issue Dec 2, 2013 · 12 comments

Comments

@rubytastic
Copy link

This gem is really good, but.. how to user a layout to render the content within?

we have
/layouts/email.html.haml

but this email is not used by maildown, how to get it to load the html email with this layout?

@schneems
Copy link
Member

schneems commented Dec 2, 2013

You should be able to specify a layout as you normally would without the gem.

If that doesn't happen, can you give me a super simple example of a new rails app that shows the problem?

@jwilsjustin
Copy link

Wondering the same here.

@schneems
Copy link
Member

Again, you would do it the same way as if you were not using maildown. If that doesn't happen, can you give me a super simple example of a new rails app that shows the problem?

@tjschuck
Copy link

@schneems Verifying that this is true.

Test app here: https://github.com/tjschuck/maildown_layout_test

Pull it down, rails s, and visit http://localhost:3000/rails/mailers/test_mailer/test_email

It should say "SOMETHING IN THE LAYOUT", but doesn't.

Step-by-step, just check the commits in order after the first one.

@schneems
Copy link
Member

The problem here is actually in how rails renders layouts. The extensions and mime types must match. To fix change the layout to a .md.erb and poof it works!

@schneems
Copy link
Member

Here's a PR that enables the layout tjschuck/maildown_layout_test#1

@schneems
Copy link
Member

Btw, if someone could give me a PR with this information in the README I would owe you many ❤️s

@tjschuck
Copy link

@schneems Oh, yeah, I already knew that changing the layout to .md would fix it. But you can't really make an HTML layout for an email in Markdown :)

It would be nice if the HTML/text versions of the emails would still respect their layouts, but the content could be written (once) in MD.

@schneems
Copy link
Member

But you can't really make an HTML layout for an email in Markdown :)

How so? By default markdown supports html, but the problem would be your text version would show up with the raw html and look awful. What in your ideal world would you like to happen? Why wouldn't you want to write your the template to your markdown email in markdown?

This library is implemented in a relatively hacky way as this part of ActionMailer was never meant to be extended, there is much we cannot change (easily) like how Rails handles templates. If I can better understand exactly what you want it might be possible to get to a workaround that achieves those goals, or to maybe build some features.

@tjschuck
Copy link

By default markdown supports html, but the problem would be your text version would show up with the raw html and look awful.

This is the problem.

The HTML that you would want in an HTML email (but not a plaintext one) would be design related HTML. Header images, CSS, etc.

@schneems
Copy link
Member

interesting so maybe only apply templates/<something>text.erb to text and templates/<something>.html.erb to html. Is this the way regular layout works? I admit mail layouts in rails are not my normal bread and butter :)

@tjschuck
Copy link

Yeah, it's supposed to use the correct layout for the correct format.

See http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-layouts, first example + comment:

class UserMailer < ActionMailer::Base
  layout 'awesome' # use awesome.(html|text).erb as the layout
end

It would be nice if the email content could be .md, get rendered into HTML/text versions via maildown, and have each format respect its parent layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants