qferr / mjml-php
一个简单的PHP库,用于将MJML渲染为HTML。
2.0.0
2022-04-09 21:34 UTC
Requires
- php: >=7.2
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-16 20:02:16 UTC
README
一个简单的PHP库,用于将MJML渲染为HTML。
在PHP中集成MJML有两种方式
- 使用MJML API
- 使用MJML库
安装
composer require qferr/mjml-php
使用MJML库
安装MJML库
npm install mjml --save
如果您需要特定版本,请使用以下语法: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> ');
使用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> ');
您可以获取API用于转换的MJML版本
$api->getMjmlVersion();
API文档中的更多详细信息:[https://mjml.io/api/documentation](https://mjml.io/api/documentation)