question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to output raw text in mjml-react?

See original GitHub issue

Hello,

We are using MGML React to output email templates that will then use handlebars when processing the final email.

For example, we have now handlebars function with named parameter format. When using React, it escapes the quote in the named parameter and breaks handlebars processing.

Neither MjmlText or MjmlRaw work.

<MjmlText>{`{{now format="YYYY"}}`}</MjmlText>
<MjmlRaw>{`{{now format="YYYY"}}`}</MjmlRaw>

outputs

<mj-text>{{now format=&#x27;YYYY&#x27;}}</mj-text>
<mj-raw>{{now format=&#x27;YYYY&#x27;}}</mj-raw>

“dangerouslySetInnerHTML” does not work either.

<MjmlText dangerouslySetInnerHTML={{ __html=`{{now format="YYYY"}}`}}/>
<MjmlText dangerouslySetInnerHTML={{ __html=`{{now format="YYYY"}}`}}/>

outputs

<mj-text dangerously-set-inner-html="[Object]"></mj-text>
<mj-raw dangerously-set-inner-html="[Object]"></mj-raw>

Any idea on how to do this in React or in MJML-React?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
mastertheblastercommented, Nov 16, 2020

I have added the MjmlHtml component as an extension as it’s not the Mjml* element. The usage looks like:

import { MjmlHtml } from 'mjml-react/extensions';

<MjmlHtml tag="span" html={`{{now format="YYYY"}}`} />
1reaction
daliusdcommented, Jul 4, 2022

Hi - bumping this - as I could not find anywhere else that addresses this issue. What can be the solution if I would like to generate the html with handlebars {{#each}}, for example

It is react library - use react for this. Otherwise you have two options:

  1. Use mjml directly. Potentially you don’t need mjml-react.
  2. Use handlebars to generate js/ts files with mjml-react
Read more comments on GitHub >

github_iconTop Results From Across the Web

mjml-guides – Documentation for MJML - The Responsive ...
Command line interface. Compiles the file and outputs the HTML generated in output.html. mjml input.mjml -o output.html.
Read more >
My Wonderful HTML Email Workflow - Josh W Comeau
I can right-click to view the raw HTML source, and copy/paste it into my mailing software. Link to this heading. Custom components with...
Read more >
Writing Emails in React - lee.david.cs Blog
Introducing MJML-React. We've identified 2 pain-points of emails in Node.js thus far. Template literals lose types and intellisense ...
Read more >
Essential Advice on How to Use MJML - Email On Acid
Find out how to get started with the MJML markup language for responsive emails. Watch an episode of Notes from the Dev and...
Read more >
mjml-group - npm
On the output HTML, remove the blank space between the two columns inside a mj-group. attribute, unit, description, default attributes. width ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found