Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qferr/mjml-twig
MJML extension for Twig
https://github.com/qferr/mjml-twig
mjml php twig
Last synced: 5 days ago
JSON representation
MJML extension for Twig
- Host: GitHub
- URL: https://github.com/qferr/mjml-twig
- Owner: qferr
- Created: 2020-04-02T15:39:12.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-27T16:06:40.000Z (over 1 year ago)
- Last Synced: 2024-10-31T05:52:07.386Z (12 days ago)
- Topics: mjml, php, twig
- Language: PHP
- Homepage: https://qferrer.medium.com/using-mjml-with-twig-cccea9af0086
- Size: 52.7 KB
- Stars: 20
- Watchers: 1
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Twig MJML extension
===================This package is a Twig extension that provides the following:
* mjml_to_html filter: processes a mjml email template.```twig
{% apply mjml_to_html %}
Hello {{ username }}
{% endapply %}
```Because we have two ways for rendering MJML to HML, the extension depends on a renderer:
* **BinaryRenderer**: using the MJML library. You will have to provide the location of the MJML binary. Don’t forget to install it with the Node package manager.
* **ApiRenderer**: using the MJML API. Nothing to install. You will have to provide the credentials to access of the API.Thanks to the library [MJML in PHP](https://github.com/qferr/mjml-php) for make easier the integration of MJML in PHP.
Read the article [Rendering MJML in PHP](https://medium.com/@qferrer/rendering-mjml-in-php-982d703aa703?source=friends_link&sk=7c5553ae7fcfcdde889bdd3b776c90a9) for more informations.Installation
------------`composer require qferr/mjml-twig`
Usage
-----```php
addExtension(new MjmlExtension($renderer));$html = $twig->render('newsletter.mjml.twig', [
'username' => 'Quentin'
]);
```You can now start using MJML in any Twig template.
Integrating in Symfony
----------------------
Register the MJML extension as a service and tag it with `twig.extension`.```yaml
# config/services.yaml
services:
# Qferrer\Mjml\Http\CurlApi:
# arguments:
# - '%env(MJML_APP_ID)%'
# - '%env(MJML_SECRET_KEY)%'# mjml_renderer:
# class: Qferrer\Mjml\Renderer\ApiRenderer
# arguments:
# - '@Qferrer\Mjml\Http\CurlApi'mjml_renderer:
class: Qferrer\Mjml\Renderer\BinaryRenderer
arguments:
- '%kernel.project_dir%/node_modules/.bin/mjml'Qferrer\Mjml\Twig\MjmlExtension:
arguments: ['@mjml_renderer']
tags: ['twig.extension']
```Source: [Using MJML with Twig](https://medium.com/@qferrer/using-mjml-with-twig-cccea9af0086?source=friends_link&sk=0271c98a6225ff216cec5faefd6d7267)