mjmlio / mjml

MJML: the only framework that makes responsive-email easy
https://mjml.io
MIT License
17.04k stars 959 forks source link

Handlebars tag support (used by mandrill) #42

Closed romainyakarouler closed 8 years ago

romainyakarouler commented 8 years ago

Hello,

Mandrill and Mailchimp support Handlebars template syntax, could we imagine a command like mjml -r template.mjml -o template.html --syntax=handlebars or mjml -r template.mjml -o template.html --syntax=mailchimp ?

Example:

replacement_html_ __users_romainnorberg_documents_jobs_web_calendrier_fonctionnel_web_template_mail

Links:

Thank u, Mjml is great!

WeshGuillaume commented 8 years ago

That's a point, but allowing multiple template languages would be heavy right? Maybe we could implement a preprocessor in another repo like mjml-hbs

arnaudbreton commented 8 years ago

Hi @romainyakarouler,

In my opinion, the role of MJML is to render a responsive HTML email layout. That said, for your use-case, I would recommend to wrap all the handlebars templating tags with an mj-raw tag so the engine keep them when rendering the MJML.

Once you have the HTML code, you can pass it to handlebar, with the right execution context so it outputs an HTML ready to be sent.

Does it make sense to you? Hope I haven't missed something here!

Let us know how that works for you!

fabien commented 8 years ago

Would it be necessary to wrap those handlebar tags in mj-raw to even keep them in the final output? I would expect those to be treated as verbatim text, but perhaps this is not possible as you say? What about non mj tags like <h1>, do we need to wrap them as well? Ideally, allowing some basic tags would make sense.

arnaudbreton commented 8 years ago

@fabien, yes, for now it is a known limitation of our engine. Because of the way we parse the DOM, we need a tag to wrap even basic text/HTML element/tags. This is actually the main reason why we needed to introduce such tag. That said, this is obviously something we're aiming to improve in a near future.

Keep you posted on our progress here!

arnaudbreton commented 8 years ago

Hey @romainyakarouler, did my comment help you moving forward on your issue? Thanks!

goldensunliu commented 8 years ago

@arnaudbreton would be nice to have an example for the mj-raw to wow the users right away. currently the documentation seems very minimal

pmorch commented 6 years ago

Also worth noting that <mj-raw> tags (apparently) need to be inside either <mj-head> or <mj-body>.

ivank commented 2 months ago

preprocessors can handle this now https://thoughtbot.com/blog/building-templated-emails-with-mjml though the vscode extension is not supporting this style yet.

I've added a PR to address this, but in the meantime have published a forked version with that feature enabled: https://marketplace.visualstudio.com/items?itemName=IvanKeirn.vscode-mjml-custom-path