![]() Add some data to inject into your template. Then inside the Node server, create a new Vue instance and use the MJML template we just created. Create a Node server to render your emails. Awesome Add some logic using Vue's template syntax. This is ideal for maintenance.Ĭonst mjml = readFileSync('email.mjml'). Start by creating an email template using MJML. Having the templating before the MJML means that you can use simple HTML tags and still benefits from MJML's CSS injection without having to copy inline CSS into your template-specific HTML. Parse the template using the MJML library - this will convert the markup to HTML.Parse the template using your templating engine - this will remove the special markup and process the if/else statements.Write MJML templates including tags that include your templating engine's markup.On our side, we decided to go with EJS, and normally you would do the following sequence: convert HTML to text which can be quite useful for email). I am using Azure Function (NodeJs) to dynamically add content to templates using handlebars and return me the final html email, which works great.I have separated sections of the template into different files (header, footer, intro etc. They are all a bit different but will allow you to do if/else logic and more (e.g. I am in the process of converting some legacy email templates to mjml (using mjml version 4.2). ![]() You have a few templating options, for example, if you are on Node.js, you have handlebars (most popular), EJS (most active), Eta (most performant), etc. if/else statements are pretty basic so they should work with any solution you pick. Once you pick your template engine, you can basically do anything that the engine allows you. In a nutshell, MJML does not support templating ( ref1, ref2). I spent quite some time trying to get this working because the documentation on this topic wasn't the friendliest at the time of writing this. ![]()
0 Comments
Leave a Reply. |