SkillAgentSearch skills...

PageMjmlToHtml

A module allowing you to write your Processwire template using MJML and get a converted HTML output using MJML API.

Install / Use

/learn @eprcstudio/PageMjmlToHtml
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

PageMjmlToHtml

A module allowing you to write your Processwire template using MJML and get a converted HTML output using MJML API.

<img width="1440" alt="Capture d’écran 2021-12-02 à 19 05 54" src="https://user-images.githubusercontent.com/6616448/144493657-8f95585c-8d25-4e33-a33e-d89a11c57ee5.png">

Modules directory: https://processwire.com/modules/page-mjml-to-html/

Support forum: https://processwire.com/talk/topic/26466-pagemjmltohtml/

About

Created by Mailjet, MJML is a markup language making it a breeze to create newsletters displayed consistently across all email clients.

Write your template using MJML combined with Processwire’s API and this module will automatically convert your code into a working newsletter thanks to their free-to-use Rest API.

Prerequisite

For this module to work you will need to get an API key and paste it in the module’s configuration.

Usage

Once your credentials are validated, select the template(s) in which you’re using the MJML syntax, save and go visualize your pages to see if everything’s good. You will either get error/warning messages or your email properly formatted and ready-to-go.

From there you can copy/paste the raw generated code in an external mailing service or distribute your newsletter using ProMailer.

You can also transpile any arbitrary MJML code by instanciating the module and using its transpile() method:

$mjml = "<mjml></mjml>";

/** @var PageMjmlToHtml $pmh */
$pmh = $modules->get("PageMjmlToHtml");

$result = $pmh->transpile($mjml);
if($result->code === 200 && empty($result->errors)) {
	echo $result->html;
}

You can read more about the function in its attached PHPDoc comment. Please note the options will default to the module’s one.

And as a bonus the method is also hookable:

$wire->addHookBefore("PageMjmlToHtml::transpile", function(HookEvent $event) {
	$mjml = $event->arguments(0);
	/** @var Page $page */
	$page = $event->arguments(1);
	$options = $event->arguments(2);

	if(!$page->id || $page->template != "specific-template") return;

	$options["relativeLinksParams"] = "utm_campaign=new-campaign-title";
	$event->arguments(2, $options);
});

Options

In the module settings, you can choose to remove the prepended/appended files when using Markup Regions.

By default the module caches the output to avoid repetitive API calls. You can add GET variables for which you would like to have different cached outputs. You can also bypass the cache altogether for specific roles.

You also have the option to convert relative URLs into absolute ones and even specify the prepended host and/or appended query parameters

Features

  • The MJML output is cached to avoid repetitive API calls
    • Not cached if there are errors/warnings
    • Cleared if the page is saved
    • Cleared if the template file has been modified
  • A simple (dumb?) code viewer highlights lines with errors/warnings
  • A button is added to quickly copy the raw code of the generated newsletter
    • Not added if the page is rendered outside of a PageView
    • Only visible to users with the page’s edit permission
  • A shortcut is also added under “View” in the edit page to open the raw code in a new tab
  • Multi-languages support
<img width="1440" alt="Capture d’écran 2021-12-02 à 21 21 45" src="https://user-images.githubusercontent.com/6616448/144499706-8efa65bc-39c5-43fc-b570-cc93670f778d.png">

Notes

The code viewer is only shown to superusers. If there’s an error the page will display:

  • Only its title for guests
  • Its title and a message inviting to contact the administrator for editors

If your layout looks weird somehow, try disabling the minification in the options.

View on GitHub
GitHub Stars12
CategoryDevelopment
Updated3mo ago
Forks1

Languages

PHP

Security Score

92/100

Audited on Dec 23, 2025

No findings