surda / mjml-nette
MJML integration into Nette Framework
v1.1.0
2019-11-09 18:58 UTC
Requires
- php: >=7.1
- ext-curl: *
- guzzlehttp/guzzle: ^6.0
- latte/latte: ^2.5
- nette/application: ^3.0
- nette/di: ^3.0
- nette/utils: ^3.0
- symfony/process: ^3.4 || ^4.0
Requires (Dev)
- nette/tester: ^2.0
- ninjify/nunjuck: ^0.3
- phpstan/phpstan: ^0.11
- phpstan/phpstan-deprecation-rules: ^0.11
- phpstan/phpstan-nette: ^0.11
- phpstan/phpstan-strict-rules: ^0.11
This package is auto-updated.
Last update: 2024-11-10 06:43:59 UTC
README
Installation
The recommended way to is via Composer:
composer require surda/mjml-nette
After that you have to register extensions in config.neon:
Binary renderer
extensions: mjml: Surda\Mjml\DI\MjmlExtension mjml.renderer: Surda\Mjml\DI\MjmlBinaryRendererExtension
List of all configuration options:
mjml: debug: %debugMode% tempDir: %tempDir%/cache/latte templateFactory: \Surda\Mjml\TemplateFactory mjml.renderer: renderer: \Surda\Mjml\Renderer\BinaryRenderer options: bin: mjml minify: FALSE validationLevel: strict beautify: TRUE
Install MJML
$ npm install -g mjml
API renderer
extensions: mjml: Surda\Mjml\DI\MjmlExtension mjml.renderer: Surda\Mjml\DI\MjmlApiRendererExtension
Minimal configuration:
mjml.renderer: options: applicationId: 'application-id' secretKey: 'secret-key'
List of all configuration options:
mjml: debug: %debugMode% tempDir: %tempDir%/cache/latte templateFactory: \Surda\Mjml\TemplateFactory mjml.renderer: renderer: \Surda\Mjml\Renderer\ApiRenderer options: applicationId: 'application-id' secretKey: 'secret-key' uri: 'https://api.mjml.io/v1/render'
Usage
Template template.mjml
<mjml> <mj-body> <mj-section> <mj-column> <mj-image width="100px" src="https://mjml.io/assets/img/logo-small.png"></mj-image> <mj-divider border-color="#F45E43"></mj-divider> <mj-text font-size="20px" color="#F45E43" font-family="helvetica">Hello {$foo}</mj-text> </mj-column> </mj-section> </mj-body> </mjml>
use Surda\Mjml\MjmlTemplateFactory; class MailSender { /** @var MjmlTemplateFactory */ private $mjmlTemplateFactory; /** * @param MjmlTemplateFactory $mjmlTemplateFactory */ public function __construct(MjmlTemplateFactory $mjmlTemplateFactory) { $this->mjmlTemplateFactory = $mjmlTemplateFactory; } public function sendEmail(): void { $template = $this->mjmlTemplateFactory->create(); $template->setFile('/path/to/template.mjml'); $template->setParameters(['foo' => 'World']); $mail = new Message; $mail->setHtmlBody($template); // or $template = $this->mjmlTemplateFactory->create(); $mail = new Message; $mail->setHtmlBody($template->renderToString('/path/to/template.mjml', ['foo' => 'World']))); // ... } }
Others
Only render *.latte template from *.mjml template
use Surda\Mjml\Engine; class Convertor { /** @var Engine */ private $engine; /** * @param Engine $engine */ public function __construct(Engine $engine) { $this->engine = $engine; } public function convert(): void { $mjmlFile = '/path/to/template.mjml'; $latteFile = $this->engine->renderLatteFile($mjmlFile); // or $mjmlFile = '/path/to/template.mjml'; $latteFile = '/path/to/template.latte'; $this->engine->renderLatteFile($mjmlFile, $latteFile); } }
More in the MJML documentation.