I’m not sure what you’re asking for, but here is a sketch of the situation I was asking about. We have a module which defines layouts for emails, e.g.:
def basic_layout(assigns) do
~H"""
<mjml>
<mj-head>
<mj-preview>{@preview}</mj-preview>
<XXX.Email.Components.head />
</mj-head>
<mj-body ...>
<mj-wrapper css-class="wrapper">
<mj-section>
<mj-column>
{render_slot(@inner_block)}
</mj-column>
</mj-section>
</mj-wrapper>
...
</mj-body>
</mjml>
"""
end
The header component, with the previously troublesome <mj-style> tag:
def head(assigns) do
~H"""
<mj-font ... />
<mj-attributes>
<mj-all ... />
<mj-button ... />
...
</mj-attributes>
<mj-style inline="inline" phx-no-curly-interpolation>
.wrapper {
border-radius: 14px;
background-color: #FFF;
border: 1px solid rgba(0,0,0,0.1);
overflow: hidden;
text-align: left;
}
.op3{
opacity: 0.3;
}
</mj-style>
"""
end
We can then use the layout in templates:
def render(assigns) do
~H"""
<XXX.Email.Layouts.basic_layout preview=@preview>
... email body ...
</XXX.Email.Layouts.basic_layout>
"""
end
Rendering the template, both for previews and actual email bodies:
def render_heex_mjml(module, template, assigns) do
{:ok, html_body} =
Phoenix.Template.render(module, template, "html", assigns)
|> Phoenix.HTML.Safe.to_iodata()
|> Enum.join()
|> Mjml.to_html()
html_body
end






















