mj-include: Add placeholders/variables
I found no practical way yet to use an external templating engine and think that this would really be helpful.
Hi @janus-reith
Some people have some successful workflow with handlebars & other templating framework. We don't want MJML to become "another templating language". While giving variables people will want conditionnal structure & so o on.
Can you share maybe your current setup so we can try to help you ?
Just wanted to give an update and saw your post, I actually found a workflow with handlebars that works. The default handlebars cli tool was not capable of simply outputting direct html or mjml syntax code, but I found render-cli on npm which does what I need.
But thanks for your offer to help. Closing this.
If someone is still interested, I made a mjml component that allows to use variables without the need of an external template engine: https://github.com/roibeart/mjml-wb-variable Probably the programming logic beneath it is unconventional and quite dirty, but it works well and saved me a lot of hassles.
Hi @roibeart
I'd like to use your component but unable to get it to work. It's likely I haven't installed it properly. Is there something more to installing beyond copying the lib folder (which only contains the .gitkeep file) and the .mjmlconfig file into the mjml project folder? What about all of the other files in the mjml-wb-variable repository?
Thanks for any help getting this working.
Hi @vaguedread, thanks to your report I realized that the lib folder didn't have the compiled file of the component... I added it now to the repository, if you copy it to your project the component should work. Sorry for the inconvenience! Let me know if you need more support.
Hi @roibeart
Thanks for responding. I'm still unable to get it to work. My installation is probably not correct since I continue to get the message that wb-variable "doesn't exist or is not registered." Attached, a screengrab of where I installed the files.

Also, the directions say to declare the variables within the mj-container. According to the mjml documentation, that component is no longer valid in v4. I tried placing my variables just below the opening mj-body tag, but no luck. What am I doing wrong?
Hi @vaguedread
You should not work inside the node_modules directory, because it has to contain only packages installed via npm.
A base mjml project is essentially a folder that contains a index.mjml file and a node_modules folder that contains the libraries mjml needs in order to work. In our case, the project requires also a lib folder that contains the code for the wb-variable component and a .mjmlconfig file that registers it: these elements have to reside at the same level of the index.mjml file (hence outside the node_modules folder).
Anyway, I noticed now that unfortunately my component doesn't work with the just released version 4 of mjml, so you need to use an older version. Here are the steps you can take to make it work:
- Create a directory: this will be your project folder
- From the terminal, enter the folder just created and install the version 3 of mjml using this command:
npm init -y && npm install mjml@^3.1.1 - Still in the project folder, paste the lib folder and the .mjmlconfig file of the wb-variable repository
- Now create your index.mjml file: hopefully now you will be able to use the component.
When I have some time I'll try to make the component compatible with the last version. If you'll face other problems please open an issue directly inside the repository, in order to keep track of it and to not go too off-topic here.
Let me know!