Closed Niesyto closed 5 months ago
Yeah you're using BodyComponent as a HeadComponent. There's no equivalent of renderMJML
for HeadComponent.
Head component can't use renderMJML
because it define the context for the body components.
If you need to do so just use the low level API, but here you seem only to need a mj-include rather than over complexify your project with custom component
mj-include won't work in my case. mj-include
is not bundled in my deployment file in AWS
mj-include
are resolved by the parser, it's not a component 🤔
I know, and that's why i can't use it. Components have to be imported and registered, so they are included in the deployment file. mj-include
is resolved by the parses, but since there's no reference to it, it's not bundled in.
I don't really follow you here if you render MJML files why you can't includes those "partial" too in your workflow ?
Even if I include this partial in the bundle, it does not get recognized by the mj-include. It seems like my setup prevents me from using it.
If you need to do so just use the low level API
What did you mean by that? It might be the solution I'm looking for
Are you using the cli or directly mjml2html if so you might need to pass the proper file path.
You can check the source code for MJML Head components to see how they push everything in the context https://github.com/mjmlio/mjml/blob/master/packages/mjml-head-style/src/index.js
I'm using mjml2html, but doing this worked well:
import { HeadComponent } from 'mjml-core';
export class PpHead extends HeadComponent {
static tagName = 'pp-head';
static endingTag = true;
handler() {
const { add } = this.context;
add('inlineStyle', '.link-nostyle { text-decoration: none }');
add('fonts', 'Inter', 'https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap');
add('defaultAttributes', 'mj-text', {
color: '#46586B',
'font-family': 'Inter, Arial',
padding: '12px 25px',
});
add('defaultAttributes', 'mj-image', { align: 'left' });
add('defaultAttributes', 'mj-button', { align: 'left', 'font-family': 'Inter, Arial' });
add('defaultAttributes', 'mj-divider', {
width: '120px',
'border-width': '1px',
'border-color': '#E7E7E7',
align: 'left',
padding: '0px 25px',
});
}
}
Describe the bug I've tried creating custom head component but it crashes during mjml2html with
TypeError: this.context.processing is not a function
errorTo Reproduce Steps to reproduce the behavior:
pp-head
export class PpHead extends HeadComponent { static endingTag = false; static tagName = 'pp-head';
render() { return this.renderMJML(`
} }