Skip to content

Instantly share code, notes, and snippets.

@notFloran
Created November 18, 2018 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notFloran/ea6bab137be628f6a0c19054e08e6906 to your computer and use it in GitHub Desktop.
Save notFloran/ea6bab137be628f6a0c19054e08e6906 to your computer and use it in GitHub Desktop.
Use MJML API with notfloran/mjml-bundle

Use MJML API with notfloran/mjml-bundle

$ composer require juanmiguelbesada/mjml-php
<?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);
}
}
# config/packages/mjml.yaml
mjml:
renderer: 'service'
options:
service_id: 'App\Mjml\ApiRenderer'
# 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