How to escape template control structures in MJML to allow them to pass through to html?
geoff-maddock opened this issue · 1 comments
geoff-maddock commented
I'm using mjml-go to process an mjml file into HTML and then html/template to do variable replacement.
In the mjml file, I'd like to be able to use control structures like if
and range
.
When I pass an mjml file that contains the code below into a call like:
htmlData, err = mjml.ToHTML(context.Background(), string(data), mjml.WithMinify(true))
The HTML does not contain the if
and range
templates, but it does contain the {{.NoteAnything}}
variable replacements.
Is there a way to allow these structures to pass through?
{{if .PreviousNotes}}
{{range .PreviousNotes}}
<mj-section background-color="#ffffff" padding="12px 0">
<mj-column>
<mj-table border="1px solid #bbbbbb" padding="0 24px" font-family="Inter">
<tr style="border-bottom: 1px solid #bbbbbb;">
<td style="padding: 8px 12px; font-size: 12px;"><span style="font-weight: 600">{{.NoteUserName}}</span>: {{.NoteUserTitle}} - {{.TicketClientName}}</td>
<td style="padding: 8px 12px; text-align: right; font-size: 12px; font-weight: 600;">{{.NoteCreatedAt}}</td>
</tr>
<tr>
<td colspan="2" style="padding: 8px 12px">
{{.NoteBody}}
</td>
</tr>
<tr>
<td colspan="2" style="padding: 8px 12px; font-size: 12px;">
<span style="font-weight: 600">Visibility:</span> {{.NoteVisibility}}
</td>
</tr>
</mj-table>
</mj-column>
</mj-section>
{{end}}
{{end}}
```
geoff-maddock commented
Looks like using the mj-raw
tag worked. Closing.
<mj-raw>
{{if .PreviousNotes}}
{{range $element := .PreviousNotes}}
</mj-raw>
...