All Projects → notFloran → mjml-bundle

notFloran / mjml-bundle

Licence: MIT license
✉️ Symfony bundle for MJML

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to mjml-bundle

TelegramBotBundle
Symfony Telegram Bot Bundle
Stars: ✭ 51 (-41.38%)
Mutual labels:  symfony-bundle
MsalsasVotingBundle
Provides voting/rating management for your Symfony project.
Stars: ✭ 14 (-83.91%)
Mutual labels:  symfony-bundle
LexikMailerBundle
This Symfony2 bundle allow you to manage some HTML email templates stored in your database. Templates are written with Twig and use I18N. You can also create some layouts to decorate your email.
Stars: ✭ 81 (-6.9%)
Mutual labels:  symfony-bundle
LoginGateBundle
No description or website provided.
Stars: ✭ 57 (-34.48%)
Mutual labels:  symfony-bundle
bundle-dependency
Symfony Bundle Dependency Component
Stars: ✭ 18 (-79.31%)
Mutual labels:  symfony-bundle
GoogleTranslateBundle
A Symfony bundle to deals with Google Translate API
Stars: ✭ 44 (-49.43%)
Mutual labels:  symfony-bundle
SpBundle
SAML2 SP Symfony Bundle based on LightSAML
Stars: ✭ 62 (-28.74%)
Mutual labels:  symfony-bundle
GuzzleBundleOAuth2Plugin
OAuth2 Plugin for GuzzleBundle
Stars: ✭ 13 (-85.06%)
Mutual labels:  symfony-bundle
DynamicParametersBundle
[UNMAINTAINED] Runtime retrieval of parameters from environment variables for Symfony
Stars: ✭ 42 (-51.72%)
Mutual labels:  symfony-bundle
SinchBundle
📦 Provides integration with Sinch.com SMS API.
Stars: ✭ 12 (-86.21%)
Mutual labels:  symfony-bundle
FkrCssURLRewriteBundle
A small assetic filter for symfony to fix all url paths at css documents to correct urls
Stars: ✭ 33 (-62.07%)
Mutual labels:  symfony-bundle
plugin-grapesjs-builder
GrapesJS HTML and MJML integration for Mautic
Stars: ✭ 42 (-51.72%)
Mutual labels:  mjml
AtoumBundle
This bundle provides a simple integration of atoum into Symfony 2.
Stars: ✭ 44 (-49.43%)
Mutual labels:  symfony-bundle
zahper
Zahper - The power of MJML into Laravel newsletters
Stars: ✭ 13 (-85.06%)
Mutual labels:  mjml
vite-bundle
Integration with your Symfony app & Vite
Stars: ✭ 56 (-35.63%)
Mutual labels:  symfony-bundle
workflower-bundle
A Symfony bundle for Workflower
Stars: ✭ 23 (-73.56%)
Mutual labels:  symfony-bundle
rss-to-email
Generate HTML emails from your RSS feeds.
Stars: ✭ 92 (+5.75%)
Mutual labels:  mjml
features-bundle
Symfony bundle for managing feature tags
Stars: ✭ 18 (-79.31%)
Mutual labels:  symfony-bundle
supervisor-bundle
Easily update your @Supervisor configuration by using annotations in Symfony commands.
Stars: ✭ 35 (-59.77%)
Mutual labels:  symfony-bundle
RulerZBundle
Symfony Bundle for RulerZ
Stars: ✭ 38 (-56.32%)
Mutual labels:  symfony-bundle

MjmlBundle

Latest Stable Version Latest Unstable Version

Bundle to use MJML 3 and 4 with Symfony >= 3.

Installation

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

$ composer require notfloran/mjml-bundle

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require notfloran/mjml-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new NotFloran\MjmlBundle\MjmlBundle(),
        ];

        // ...
    }

    // ...
}

Renderer

For the moment only one renderer is available, the binary renderer.

Binary

Install MJML

$ npm install mjml

Then you need to update the configuration:

# config/packages/mjml.yaml
mjml:
  renderer: binary # default: binary
  options:
    binary: '%kernel.project_dir%/node_modules/.bin/mjml' # default: mjml
    node: '/Users/user/.nvm/versions/node/v10.16.0/bin/node' # default: null
    minify: true # default: false
    validation_level: skip # default: strict. See https://mjml.io/documentation/#validating-mjml

The node option is there for those who have problems with $PATH, see #35.

Custom

First you must create a class which implements NotFloran\MjmlBundle\Renderer\RendererInterface, then declare it as a service.

And finally you have to change the configuration:

# config/packages/mjml.yaml
mjml:
    renderer: 'service'
    options:
        service_id: 'App\Mjml\MyCustomRenderer'

PHP Config

If you're using symfony 5 and want to configure this bundle with PHP files instead of YAML:

// config/packages/mjml.php
<?php declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $configurator): void
{
    $configurator->extension('mjml', [
        'renderer' => 'binary',
        'options' => [
            'binary' => '%kernel.project_dir%/node_modules/.bin/mjml',
            'minify' => true,
            'validation_level' => 'skip'
        ]
    ]);
};

API

The bundle has no official integration with the MJML API.

You can create your own integration by using juanmiguelbesada/mjml-php and following this gist : https://gist.github.com/notFloran/ea6bab137be628f6a0c19054e08e6906.

Usage

Use "mjml" twig tag

{# mail/example.mjml.twig #}
{% block email_content %}
    {% 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 {{ name }} from MJML and Symfony
                        </mj-text>

                    </mj-column>
                </mj-section>
        </mj-body>
    </mjml>
    {% endmjml %}
{% endblock %}
public function sendEmail(MailerInterface $mailer)
{
    // The MJMl body is rendered by the mjml tag in the twig file
    $htmlBody = $this->renderView('templates/mail/example.mjml.twig', ['name' => 'Floran']);

    $email = (new Email())
        ->from('[email protected]')
        ->to('[email protected]')
        ->subject('Hello from MJML!')
        ->html($htmlBody);

    $mailer->send($email);

    // ...
}

Use "mjml" service

{# templates/mail/example.mjml.twig #}
<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 {{ name }} from MJML and Symfony
                    </mj-text>

                </mj-column>
            </mj-section>
    </mj-body>
</mjml>
use NotFloran\MjmlBundle\Renderer\RendererInterface;

// ...

public function sendEmail(MailerInterface $mailer, RendererInterface $mjml)
{
    $mjmlBody = $this->renderView('templates/mail/example.mjml.twig', ['name' => 'Floran']);
    $htmlBody = $mjml->render($mjmlBody);

    $email = (new Email())
        ->from('[email protected]')
        ->to('[email protected]')
        ->subject('Hello from MJML!')
        ->html($htmlBody);

    $mailer->send($email);

    // ...
}

SwiftMailer integration

This integration is deprecated and will be removed in the next major version.

Declare the following service:

NotFloran\MjmlBundle\SwiftMailer\MjmlPlugin:
    tags: [swiftmailer.default.plugin]

Create a SwiftMailer message with a MJML body (without {% mjml %}) and with text/mjml as content-type:

$message = (new \Swift_Message('Hello Email'))
    ->setFrom('[email protected]')
    ->setTo('[email protected]')
    ->setBody(
        $this->renderView('mail/example.mjml.twig'),
        'text/mjml'
    );

$mailer->send($message);

The plugin will automatically render the MJML body and replace the body with the rendered HTML.

In the case where a spool is used: the MJML content is save in the spool and render when the spool is flushed.

License

MjmlBundle is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].