Mjml: Confused about variables

Created on 28 Oct 2018  路  6Comments  路  Source: mjmlio/mjml

I'm sure this is a question that gets asked all the time, but I wanted to report my confusion about how MJML handles variables, if at all.

Looking at https://mjml.io/documentation/ I can't see any technique to interpolate variables similar to Handlebars' {{ foo }} or JSX' { bar }.

On the other hand this post from just a few months ago mentions a {% set gender = var:user.gender %} syntax

Is that deprecated? If so how do you do something a simple as showing a user's name? (such as the "Hello, Helen" heading from the tutorial).

I feel like even if MJML doesn't support variables anymore, the documentation should include a section about workarounds, because this is going to be one of the first questions anybody new to the library has.

Most helpful comment

I get it now, but I think that explanation should be in the docs somewhere. I had assumed MJML was a replacement for Handlebars, where it's actually more of a replacement for HTML; meaning you still need Handlebars or an equivalent to generate it.

Maybe it's just me but that wasn't obvious at all at first.

All 6 comments

There is no mention of any templating language in the documentation simply because there isn't any built-in templating language in MJML (and never has been). You're indeed confusing MJML with Mailjet's template language.

MJML is a markup language aimed at making it easy to create responsive emails.

For templating, you're free to use any template language of your choice, such as Mailjet's template language (which you linked) or https://github.com/pugjs/pug or any other.

I get it now, but I think that explanation should be in the docs somewhere. I had assumed MJML was a replacement for Handlebars, where it's actually more of a replacement for HTML; meaning you still need Handlebars or an equivalent to generate it.

Maybe it's just me but that wasn't obvious at all at first.

@SachaG : Thanks for your question. I'm confused as well

But it just makes a lot of sense to provide templating feature in-the-box.
The whole project is designed for developer usage, so i think this is essential to have.

Not having template support just makes the whole process redundantly complicated.

  1. create mjml file
  2. create template definitions
  3. custom scripts for replacing or using handlebar for static mjml file
  4. convert mjml file to html
  5. and on

Thoughts? :)

Everything could be automated or integrated in any nodeJS project. We even have browser build now so any templating lang should be easy to plug. There's a detailed issue where we explain why we won't do this here : #1630

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kytosai picture kytosai  路  4Comments

liminspace picture liminspace  路  3Comments

samatcd picture samatcd  路  4Comments

ghost picture ghost  路  4Comments

zarikadzer picture zarikadzer  路  3Comments