wishthis/vendor/qferr/mjml-php
2022-11-28 11:29:52 +01:00
..
.github/workflows Update qferr/mjml-php to v2.0.0 2022-11-28 11:29:52 +01:00
src Update qferr/mjml-php to v2.0.0 2022-11-28 11:29:52 +01:00
tests Update qferr/mjml-php to v2.0.0 2022-11-28 11:29:52 +01:00
.gitignore Update qferr/mjml-php to v2.0.0 2022-11-28 11:29:52 +01:00
composer.json Update qferr/mjml-php to v2.0.0 2022-11-28 11:29:52 +01:00
composer.lock Update qferr/mjml-php to v2.0.0 2022-11-28 11:29:52 +01:00
package-lock.json Update qferr/mjml-php to v2.0.0 2022-11-28 11:29:52 +01:00
package.json Update qferr/mjml-php to v2.0.0 2022-11-28 11:29:52 +01:00
phpunit.xml.dist Update qferr/mjml-php to v2.0.0 2022-11-28 11:29:52 +01:00
README.md Update qferr/mjml-php to v2.0.0 2022-11-28 11:29:52 +01:00

MJML in PHP

PHPUnit

A simple PHP library to render MJML to HTML.

There are two ways for integrating MJML in PHP:

  • using the MJML API
  • using the MJML library

Installation

composer require qferr/mjml-php

Using MJML library

Install the MJML library:

npm install mjml --save

If you want a specific version, use the following syntax: npm install mjml@4.7.1 --save

<?php
require_once 'vendor/autoload.php';

$renderer = new \Qferrer\Mjml\Renderer\BinaryRenderer(__DIR__ . '/node_modules/.bin/mjml');

$html = $renderer->render('
    <mjml>
        <mj-body>
            <mj-section>
                <mj-column>
                    <mj-text>Hello world</mj-text>
                </mj-column>
            </mj-section>
        </mj-body>
    </mjml>
');

Using MJML API

<?php
require_once 'vendor/autoload.php';

$apiId = 'abcdef-1234-5678-ghijkl';
$secretKey = 'ghijkl-5678-1234-abcdef';

$api = new \Qferrer\Mjml\Http\CurlApi($apiId, $secretKey);
$renderer = new \Qferrer\Mjml\Renderer\ApiRenderer($api);

$html = $renderer->render('
    <mjml>
        <mj-body>
            <mj-section>
                <mj-column>
                    <mj-text>Hello world</mj-text>
                </mj-column>
            </mj-section>
        </mj-body>
    </mjml>
');

You can get the version of MJML used by the API to transpile:

$api->getMjmlVersion();

More details in the API documentation: https://mjml.io/api/documentation