$ composer require juanmiguelbesada/mjml-php
Created
November 18, 2018 10:50
-
-
Save notFloran/ea6bab137be628f6a0c19054e08e6906 to your computer and use it in GitHub Desktop.
Use MJML API with notfloran/mjml-bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# src/Mjml/ApiRenderer.php | |
namespace App\Mjml; | |
use Mjml\Client; | |
use NotFloran\MjmlBundle\Renderer\RendererInterface; | |
class ApiRenderer implements RendererInterface | |
{ | |
/** | |
* @var Client | |
*/ | |
private $client; | |
public function __construct(Client $client) | |
{ | |
$this->client = $client; | |
} | |
public function render(string $mjmlContent): string | |
{ | |
return $this->client->render($mjmlContent); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/packages/mjml.yaml | |
mjml: | |
renderer: 'service' | |
options: | |
service_id: 'App\Mjml\ApiRenderer' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/services.yaml | |
services: | |
mjml_api: | |
class: Mjml\Client | |
arguments: | |
- 'application-id' | |
- 'secret-key' | |
App\Mjml\ApiRenderer: | |
arguments: | |
- '@mjml_api' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment