Skip to content

moox/mjml Docs #1080

Description

@adrolli

moox MJML

MJML](https://mjml.io/) is a markup language designed to reduce the pain of coding responsive emails. moox MJML converts MJML to HTML, without requiring Node.js for most use cases.

moox MJML is compatible with spatie/mjml-php, so you can use it as a drop-in replacement.

Behind the scenes, moox MJML uses shyim/mjml-php for all supported features. This provides native PHP rendering without spawning Symfony Process, discovering a Node.js binary, or requiring Node.js to be installed.

This covers most capabilities needed to render MJML emails. Only features not supported by the native PHP renderer are delegated to the Node.js-based renderer.

Requirements

This package requires

For the compatibility matrix (PHP, Laravel and Filament) please refer to the moox Docs.

Installation

composer require moox/mjml
php artisan moox/install

Manual installation

Instead of using the moox Installer, you can:

Discover or install NodeJS, see - moox Node.

Install the mjml Node package:

npm install mjml

Publish the config if you want a local copy:

php artisan vendor:publish --tag=mjml-config

Usage

Here's an example of how to use moox/mjml:

use Moox\Mjml\Mjml;

$mjml = <<<'MJML'
    <mjml>
      <mj-body>
        <mj-section>
          <mj-column>
            <mj-text invalid-attribute>Hello World</mj-text>
          </mj-column>
        </mj-section>
      </mj-body>
    </mjml>
    MJML;

$html = Mjml::new()->toHtml($mjml);

The returned HTML will be compatible with a wide range of mail clients and browsers.

Mail templating in Filament

Want to have a convenient UI for creating mail layouts and templates? Use moox Mail Template.

Internal API

use Moox\Mjml\Enums\ValidationLevel;
use Moox\Mjml\Mjml;

$html = Mjml::new()->toHtml($mjml);

$result = Mjml::new()->convert($mjml);
$result->html();
$result->hasErrors();
$result->errors();

Mjml::new()->canConvert($mjml);
Mjml::new()->canConvertWithoutErrors($mjml);

$minified = Mjml::new()->minify()->toHtml($mjml);
$checked = Mjml::new()->validationLevel(ValidationLevel::Soft)->convert($mjml);

The fluent methods follow the Spatie mjml-php surface: keepComments(), hideComments(), ignoreIncludes(), beautify(), minify(), validationLevel(), filePath(), workingDirectory(), and sidecar(). toHtml() and convert() also accept an options array as the second argument; array values override fluent ones.

Comparison

Die Kompatibilitäts-Tabelle ist gut, sollte aber nach Überarbeitung des Packages entsprechend umgeschrieben werden.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions