boostport / mjml-go Goto Github PK
View Code? Open in Web Editor NEWCompile MJML to HTML directly in your Go applications!
License: Apache License 2.0
Compile MJML to HTML directly in your Go applications!
License: Apache License 2.0
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}}
```
I'm using mjml 0.14.6 in a project to compile an mjml file to html. I'm hitting an error when using "mj-repeat".
{"error":"MJML compilation error:\n- Line 114 of (mj-text) - Attribute mj-repeat is illegal","level":"error","msg":"Failed to generate html email body","time":"2024-04-03T23:24:19Z"}
Is this a known issue, or something that might be a config issue on my end?
Hi,
Latest release v0.7.0
fails with(go get -u
):
... github.com/Boostport/mjml-go imports
github.com/tetratelabs/wazero/wasi_snapshot_preview1: cannot find module providing package github.com/tetratelabs/wazero/wasi_snapshot_preview1
A new release is needed.
For temporary solution:
go get github.com/Boostport/mjml-go@cef2972
Thanks
New version(v1.0.0-pre.8) of wazero breaks this lib
../../../../go/pkg/mod/github.com/!boostport/[email protected]/mjml.go:288:20: too many arguments in call to r.NewHostModuleBuilder("env").NewFunctionBuilder().WithFunc(returnResult).WithParameterNames("ptr", "len", "ident").Export("return_result").NewFunctionBuilder().WithFunc(func(_ uint32, _ uint32, _ uint32) uint32 {…}).Export("get_static_file").NewFunctionBuilder().WithFunc(func(_ uint32, _ uint32, _ uint32, _ uint32, _ uint32, _ uint32) uint32 {…}).Export("request_set_field").NewFunctionBuilder().WithFunc(func(_ uint32, _ uint32, _ uint32, _ uint32, _ uint32) {…}).Export("resp_set_header").NewFunctionBuilder().WithFunc(func(_ uint32, _ uint32, _ uint32) uint32 {…}).Export("cache_get").NewFunctionBuilder().WithFunc(func(_ uint32, _ uint32, _ uint32, _ uint32, _ uint32) uint32 {…}).Export("add_ffi_var").NewFunctionBuilder().WithFunc(func(_ uint32, _ uint32) uint32 {…}).Export("get_ffi_result").NewFunctionBuilder().WithFunc(func(_ uint32, _ uint32, _ uint32, _ uint32) {…}).Export("return_error").NewFunctionBuilder().WithFunc(func(_ uint32, _ uint32, _ uint32, _ uint32, _ uint32, _ uint32) uint32 {…}).Export("fetch_url").NewFunctionBuilder().WithFunc(func(_ uint32, _ uint32, _ uint32, _ uint32, _ uint32) uint32 {…}).Export("graphql_query").NewFunctionBuilder().WithFunc(func(_ uint32, _ uint32, _ uint32, _ uint32) uint32 {…}).Export("db_exec").NewFunctionBuilder().WithFunc(func(_ uint32, _ uint32, _ uint32, _ uint32, _ uint32, _ uint32) uint32 {…}).Export("cache_set").NewFunctionBuilder().WithFunc(func(_ uint32, _ uint32, _ uint32, _ uint32) uint32 {…}).Export("request_get_field").NewFunctionBuilder().WithFunc(func(ctx context.Context, m api.Module, ptr uint32, size uint32, level uint32, ident uint32) {…}).Export("log_msg").Instantiate
have (context.Context, wazero.Runtime)
want (context.Context)
Hey @F21 , thanks for this package! It comes in very handy for a project we're currently working on 🙌
I just wanted to ask if you have any similar solution or know of any alternatives for using custom mjml components in go as well?
Mjml's proposed solution seems quite javascript heavy
(Sorry for asking this as an issue, didn't come up with any better way of reaching out)
I want to format the following template but I get this error in the jsonResult (res) object at the time of making the json.Unmarshal (mjml.go line 204)
Template:
<mjml> <mj-body background-color="#fff"> <mj-section background-color="#ef6451"> <mj-column> <mj-navbar base-url="https://link.com" hamburger="hamburger" ico-color="#ffffff"> <mj-navbar-link href="#" color="#ffffff">Nav1</mj-navbar-link> <mj-navbar-link href="#" color="#ffffff">Nav2</mj-navbar-link> <mj-navbar-link href="#" color="#ffffff">Nav3</mj-navbar-link> <mj-navbar-link href="#" color="#ffffff">Nav4</mj-navbar-link> <mj-navbar-link href="#" color="#ffffff">Nav5</mj-navbar-link> </mj-navbar> </mj-column> </mj-section> <mj-section full-width="full-width"> <mj-column> <mj-text align="center" font-size="20px"> {{ title }} </mj-text> </mj-column> </mj-section> <mj-section> <mj-column> <mj-button font-family="Helvetica" background-color="#f45e43" color="white"> Button 1 </mj-button> </mj-column> <mj-column> <mj-button font-family="Helvetica" background-color="#f45e43" color="white"> Button 2 </mj-button> </mj-column> <mj-column> <mj-button font-family="Helvetica" background-color="#f45e43" color="white"> Button 3 </mj-button> </mj-column> </mj-section> </mj-body> </mjml>
Err: Secure random number generation is not supported by this browser. Use Chrome, Firefox or Internet Explorer 11
Im using a IDE to test it and go 1.18.2.
I execute the method with these options:
mjml.ToHTML(context.Background(), stringTemplate, mjml.WithFonts(mjml.Fonts{}), mjml.WithBeautify(true), mjml.WithMinify(true), mjml.WithValidationLevel("skip"))
After several tests I know that the error comes from the section that includes the navbar, it only happens when the navbar is added.
Any recommendations? Is this a limitation of the package?
Could you update the mjml version to the newest one? current: 4.12.0, newest: 4.14.1
Thank you!
Hi, first and foremost, thank you for working on this.
Here is the situation:
I am running mjml-go inside an app, I read an .mjml
file and then call mjml.toHTML(fileContent)
. When I run the app locally everything works fine, I also wrote some tests around the mjml functionality in my app, and when tests run, everything works fine (ie mjml compiles to HTML).
Now, I deployed my app in an EKS cluster and the app is running fine, but when the time comes to compile mjml I am getting the following error:
error: input is missing mjml property
that error seems to come from the JS compile function here
and that gets called from the go binding here
I wonder why would the property seem to be missing on my live app whereas in other instances it compiles just fine (and I also made a small toy app to test it out and of course that is working too!)
I guess my issue here is I can't be sure what that json payload looks like on the JS side, and perhaps would be nice to have some way of telling what is happening with the payload that it lacks the proper content for some reason!
any tips/pointers on how to approach this issue?
Hey
The could be done using WASI ?
requires FS access and wazero WASI provides this.
https://github.com/tetratelabs/wazero/tree/main/imports/wasi_snapshot_preview1/example#wasi-example
https://github.com/tetratelabs/wazero/blob/main/imports/wasi_snapshot_preview1/example/cat.go is a basic working example
Is it possible to create custom MJLML components? If not, any workarounds you can suggest?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.