Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow arbitrary value inside mj-raw #252

Open
thiamsantos opened this issue Jan 27, 2022 · 5 comments
Open

Allow arbitrary value inside mj-raw #252

thiamsantos opened this issue Jan 27, 2022 · 5 comments
Labels
wontfix This will not be worked on

Comments

@thiamsantos
Copy link

First of all thanks for the awesome library.

I'm trying to add templating tags directly inside mjml. According to the docs https://documentation.mjml.io/#mj-raw we can accomplish it using the mj-raw tag.

Right now mrml seems to support only valid html inside the tags. Would be nice if we could pass any arbitrary value inside the mjml to be able to latter pass the generated html to our templating engine.

Examples of the mjml code:

<mjml>
  <mj-body>
    <mj-raw>
      {% if foo < 5 %}
    </mj-raw>
      <!-- Some mjml section -->
    <mj-raw>
      {% endif %}
    </mj-raw>
  </mj-body>
</mjml>
<mjml>
  <mj-body>
    <mj-raw>
      <%= @foo %>
    </mj-raw>
  </mj-body>
</mjml>

If this feature is welcoming, I would be happy to send a PR for it, I would probably just need to some guidance on the code.

@jdrouet jdrouet self-assigned this Jan 27, 2022
@jdrouet jdrouet added the enhancement New feature or request label Jan 27, 2022
@jdrouet jdrouet removed their assignment Jan 27, 2022
@jdrouet jdrouet removed the enhancement New feature or request label Jan 27, 2022
@jdrouet
Copy link
Owner

jdrouet commented Jan 27, 2022

@thiamsantos if you take a look at Catapulte, I ran into the same problem and ended up putting a template management system on top of MRML.
Like it's not the job of HTML to do that, I think MRML/MJML shouldn't have to do that as well. There are many templating libraries out there 😄
But of course, I'm open to discussion 😉

@jdrouet jdrouet added the wontfix This will not be worked on label Jan 27, 2022
@thiamsantos
Copy link
Author

thiamsantos commented Jan 27, 2022

ended up putting a template management system on top of MRML

That's basically the approach that I'm taking today. Using a template engine to generate the mjml and then converting the final MJML directly to HTML right before sending the email. (templated MJML -> MJML -> HTML)

In my use case, by allowing putting the special tags inside the mj-raw I could run the MJML conversion to HTML in compile time, and avoid the conversion on every email send. (templated MJML -> templated HTML -> HTML)

@tomciopp
Copy link

It looks like the standard for this is to use a comment before the invalid html.

<mjml>
 <mj-body>
   <mj-raw>
     <!-- htmlmin:ignore -->{% if foo < 5 %}<!-- htmlmin:ignore -->
   </mj-raw>
     <!-- Some mjml section -->
   <mj-raw>
     {% endif %}
   </mj-raw>
 </mj-body>
</mjml>

Right now this will return a parse error. I feel like it should correctly do what mjml expects it to do, which is compile. LMKWYT.

@marcelolx
Copy link

marcelolx commented Dec 15, 2023

We have been facing a similar issue, but it is not exactly related to templating and more because MRML expects valid HTML within a mj-raw element... We have some emails that will contain something like the following

<mjml>
  <mj-body>
    <mj-raw>
      <span>Some text that we don't control with a chevron <> that MRML is raising an error</span>
    </mj-raw>
  </mj-body>
</mjml>

We tried the following 👇 but that didn't work either

{% if foo < 5 %}

<mjml>
  <mj-body>
    <mj-raw>
      <!-- htmlmin:ignore -->
      <span>Some text that we don't control with a chevron <> that MRML is raising an error</span>
      <!-- htmlmin:ignore -->
    </mj-raw>
  </mj-body>
</mjml>

PS: We solved this by escaping <>, but still, it feels unexpected for MRML to expect valid HTML in there... (<> -> &lt;&gt;)

@jdrouet
Copy link
Owner

jdrouet commented Dec 16, 2023

Thanks for the feedback. I didn't find a good parsing library that handles all those cases yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants