Can't extract mjml, body, head (and its components) into a custom component #2743
Answered
by
iRyusa
mabouguerra
asked this question in
Q&A
Replies: 3 comments 3 replies
-
Yeah this is not supported. MJML root tag is not something you can
substitue inside a custom component.
…On Sat, Sep 9, 2023 at 6:57 PM Mohamed Amine ***@***.***> wrote:
Hello!
I have followed this https://github.com/mjmlio/mjml-component-boilerplate,
and created many components alright, but when I tried to create a component
that would abstract the head and body tags like this:
<mjml>
<mj-head>
<mj-font name="custom font" .../>
<mj-attributes>
<!--custom attribute values -->
</mj-attributes>
</mj-head>
<mj-body width="custom width" ...>
<mj-column>
<!-- email content -->
</mj-body>
</mjml>
But the .mjml templates wouldn't compile, complaining about the structure
and missing mjml and body tags.
So I tried to only extract the head into a component, and although the
templates compile but it has no effect: no font and no attribute values are
applied.
Then I tried to extract some parts of the head into sub-components like
mj-custom-front and mj-custom-attributes and put them in the head of the
templates but I get an error when I try to compile the tempates.
Any ideas? Thanks!
—
Reply to this email directly, view it on GitHub
<#2743>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAELHTJU3OSH6Z336RYNIWLXZSNXZANCNFSM6AAAAAA4RR2EOQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Just use the primitives and push what you need inside the head like you
would do in mj-font or mj-attributes component code.
Keep in mind that head is always executed first because it will have some
side effect on attributes for body elements.
Generally speaking it's a bad practice to use custom component to override
layout, just use a templating language like mustache/pugjs or w/e that
support it https://pugjs.org/language/inheritance.html
…On Sat, Sep 9, 2023 at 7:06 PM Mohamed Amine ***@***.***> wrote:
Thanks @iRyusa <https://github.com/iRyusa> for the quick reply. What
about extracting the whole head tag (which had no effect when I tried) or
its sub components like font and attributes which fail to compile?
—
Reply to this email directly, view it on GitHub
<#2743 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAELHTOQQF7ODQRV3EAQJHLXZSOZHANCNFSM6AAAAAA4RR2EOQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
mabouguerra
-
https://github.com/mjmlio/mjml/blob/master/packages/mjml-head-attributes/src/index.js
Just check how it's done in standard component in do the same.
… Message ID: ***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I have followed this https://github.com/mjmlio/mjml-component-boilerplate, and created many components alright, but when I tried to create a component that would abstract the
head
andbody
tags like this:But the
.mjml
templates wouldn't compile, complaining about the structure and missingmjml
andbody
tags.So I tried to only extract the
head
into a component, and although the templates compile but it has no effect: no font and no attribute values are applied.Then I tried to extract some parts of the
head
into sub-components likemj-custom-front
andmj-custom-attributes
and put them in the head of the templates but I get an error when I try to compile the tempates.Any ideas? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions