Replies: 3 comments 2 replies
-
It's really a niche need with not so many use case. I don't think we'll
provide anything like that
…On Thu, Jan 12, 2023 at 4:28 PM Mikael Finstad ***@***.***> wrote:
Given that it's possible to define the document using JSON, I would love
to be able to include such JSON partials from a mjml xml document.
This would allow users to easily customise parts of the content of their
emails using the JSON structure created from JS code, while still providing
an overall layout defined in mjml. This eliminates the need to use a
templating language for replacing placeholders etc in the mjml document,
and would eliminate all issues related to correctly escaping and injection
attacks with untrusted data.
Example mj-include could have a json option:
// template.mjml
<mjml>
<mj-body>
<mj-include path="header.mjml" />
<mj-include json="mytable" />
<mj-include path="footer.mjml" />
</mj-body>
</mjml>
Then when rendering to html, we could inject this JSON:
const mytable = {
tagName: 'mjml',
attributes: {},
children: [{
tagName: 'mj-body',
attributes: {},
children: [{
tagName: 'mj-section',
attributes: {},
children: [{
tagName: 'mj-column',
attributes: {},
children: [{
tagName: 'mj-image',
attributes: {
'width': '100px',
'src': '/assets/img/logo-small.png'
}
},
{
tagName: 'mj-divider',
attributes: {
'border-color' : '#F46E43'
}
},
{
tagName: 'mj-text',
attributes: {
'font-size': '20px',
'color': '#F45E43',
'font-family': 'Helvetica'
},
content: 'Hello World'
}]
}]
}]
}]};
const mjml = fs.readFileSync('template.mjml', 'utf-8');const { html } = mjml2html(mjml, { json: { mytable } });
—
Reply to this email directly, view it on GitHub
<#2619>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAELHTOB3OUHN2DWDOLVKXDWSAPKPANCNFSM6AAAAAATZMHWE4>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
For templating, we let users plug any templating lang they want to MJML. If
we open template features to MJML, people will ask for
conditionnals/for-loops/... so we won't add anything like that to MJML.
As you're already in node ecosystem, you can use
Handlebars/MustacheJS/PugJs/...
|
Beta Was this translation helpful? Give feedback.
1 reply
-
I created a library btw I love the simplicity of mjml and the fact that you don't do custom templating tags etc, just pure XML. The fact that mjml maps so well to JSON removes the need for it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Update: I created a library
mjml-dynamic
for this.Given that it's possible to define the document using JSON, I would love to be able to include such JSON partials from a mjml xml document.
This would allow users to easily customise parts of the content of their emails using the JSON structure created from JS code, while still providing an overall layout defined in mjml. This eliminates the need to use a templating language for replacing placeholders etc in the
mjml
document, and would eliminate all issues related to correctly escaping and injection attacks with untrusted data.Example
mj-include
could have ajson
option:Then when rendering to html, we could inject this JSON:
Beta Was this translation helpful? Give feedback.
All reactions