zellien/zellien-mjml
最新稳定版本:v1.0.1
Composer 安装命令:
composer require zellien/zellien-mjml
包简介
PHP library for rendering MJML templates
README 文档
README
PHP library for rendering MJML templates
Installation
The preferred method of installation is via Composer. Run the following command to install the package and add it as a requirement to your project's
composer require zellien/zellien-mjml
Usage
Create an instance of the MjmlRenderer class by passing the configuration array to the constructor. The configuration array should contain the application_id and secret_key as non-empty strings.
Call the render method on the $renderer object, passing the MJML template as a non-empty string. It will return the rendered HTML as a non-empty string.
$mjmlTemplate = '<mjml>Your MJML template goes here</mjml>'; $renderedHtml = $renderer->render($mjmlTemplate);
Handle the potential exceptions that can be thrown by the render method:
BadRequestExceptionif the request is invalid.UnauthorizedExceptionif authentication fails.ForbiddenExceptionif the request is unauthorized.UnexpectedErrorExceptionif an unexpected error occurs.
try { $renderedHtml = $renderer->render($mjmlTemplate); } catch (BadRequestException $e) { // Handle bad request error } catch (UnauthorizedException $e) { // Handle unauthorized error } catch (ForbiddenException $e) { // Handle forbidden error } catch (UnexpectedErrorException $e) { // Handle unexpected error }
Additional Notes
Make sure you have the necessary dependencies installed, such as the cURL extension.
Ensure that the API URL (https://api.mjml.io/v1/render) is accessible from your environment.
That's it! You can now utilize the MjmlRenderer library in your project to render MJML templates using the API.
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-22