首先,我是电子邮件标记的新手。因此,我决定使用mjml构造一个字母,但我遇到了问题-标记无法正确呈现: MJML不包含组件,我也不明白为什么。使用npm包mjml-component-boilerplate创建了项目,因为我想注册自己的组件。
我的index.mjml
<mj-body>
<mj-include path="./components/blocks/header.mjml" />
<mj-include path="./components/blocks/main.mjml" />
<mj-include path="./components/blocks/footer.mjml" />
</mj-body>
输出index.html的一部分(与main.mjml和footer.mjml相同)
<div>
<!-- mj-include fails to read file : ./components/blocks/header.mjml at D:\projects\ctc_projects\chetv\site\reshala_promo\email\components\blocks\header.mjml -->
header.mjml
<mj-section>
<mj-column>
<mj-div css-class="header">
<mj-image
src="/assets/images/logo.png"
alt="ЧЕ!"
title="https://chetv.ru/"
href="https://chetv.ru/"
target="__blank"
css-class="header__logo"
/>
</mj-div>
</mj-column>
</mj-section>
在某种情况下,如果我的MjDiv组件有意义的话
import { registerDependencies } from 'mjml-validator'
import { BodyComponent } from 'mjml-core'
registerDependencies({
'mj-body': ['mj-div'],
'mj-column': ['mj-div'],
'mj-section': ['mj-div'],
'mj-div': [
'mj-text', 'mj-image', 'mj-accordion',
'mj-carousel', 'mj-divider', 'mj-group',
'mj-navbar', 'mj-raw', 'mj-social',
'mj-div', 'mj-a', 'mj-p', 'mj-h1'
]
});
export default class MjDivComponent extends BodyComponent {
static endingTag = true;
static allowedAttributes = {
'css-class': 'css-class',
'style': 'style'
};
render() {
return `<div
${this.htmlAttributes({
class: this.getAttribute('css-class'),
style: this.getAttribute('style')
})}
>${this.getContent()}</div>`;
}
}
答案 0 :(得分:1)
您演示了将<mj-include>
组件放在<mj-body>
之后(如https://mjml.io/documentation/#mj-include所示)。在那里对我不起作用。
当我将<mj-include>
元素放在<mj-head>
之后,对我来说有用。祝你好运!
我将您的其余帖子解释为背景,而不是问其他问题。让我知道是否可以。
顺便说一句:除了stackoverflow,MJML信息的另一个重要来源是https://mjml.slack.com。
答案 1 :(得分:0)
<mj-section padding="0px">
<mj-column>
<mj-text align="center" padding="0px">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</mj-text>
</mj-column>
</mj-section>
答案 2 :(得分:-1)
您包含的文件丢失了mj-wrapper
<mj-wrapper>
<mj-section>
<mj-column>
... Content here
</mj-column>
</mj-section>
</mj-wrapper>
没有mj-wrapper,您的MJML无效代码。