Developed with love by KnpLabs Hire us for your project!
38

mjml-bundle

by notFloran

✉️ Symfony bundle for MJML

MjmlBundle

Latest Stable Version
Latest Unstable Version

Bundle to use MJML with Symfony 4.

Installation

Download the bundle:

composer require notfloran/mjml-bundle

Configuration

Example:

# config/packages/notfloran_mjml.yaml
mjml:
    bin: '%kernel.project_dir%/node_modules/.bin/mjml' # default:  mjml
    mimify: true # default: false

Usage

Use service

{# templates/mail/example.mjml.twig #}
<mjml>
    <mj-body>
            <mj-section>
                <mj-column>

                    <mj-image width="100" 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>
$message = (new \Swift_Message('Hello Email'))
    ->setFrom('my-app@example.fr')
    ->setTo('me@example.fr')
    ->setBody(
        $this->get('mjml')->render(
            $this->get('twig')->render('templates/mail/example.mjml.twig', [
                'name' => 'Floran'
            ])
        ),
        'text/html'
    )
;

$this->get('mailer')->send($message);

Use twig tag

{# mail/example.mjml.twig #}
{% block email_content %}
    {% mjml %}
    <mjml>
        <mj-body>
                <mj-section>
                    <mj-column>

                        <mj-image width="100" 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 %}
$message = (new \Swift_Message('Hello Email'))
    ->setFrom('my-app@example.fr')
    ->setTo('me@example.fr')
    ->setBody(
        $this->get('twig')->render('templates/mail/example.mjml.twig', [
            'name' => 'Floran'
        ]),
        'text/html'
    )
;

$this->get('mailer')->send($message);

License

MjmlBundle is licensed under the MIT license.

MIT License

Copyright (c) 2017 Floran Brutel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
  • Update examples for MJML 4
    By notFloran, 8 months ago
  • Merge pull request #7 from notFloran/travis
    By web-flow, 8 months ago
  • Add dependency-injection
    By notFloran, 8 months ago
  • Enable travis integration
    By notFloran, 8 months ago
  • Merge pull request #8 from augustinfla/sf4
    By web-flow, 8 months ago
  • Merge branch 'master' into sf4
    By web-flow, 8 months ago
  • Add compatibility with SF4
    By , 8 months ago
  • Use local binary for example
    By web-flow, 1 year ago
  • Fix some errors reported by phpstan
    By notFloran, 1 year ago
  • add badge for packagist
    By web-flow, 1 year ago
  • Merge pull request #2 from notFloran/throw-exception-for-mjml-syntax-error
    By web-flow, 1 year ago
  • Set level of mjml to strict to throw exception when syntax is invalid
    By notFloran, 1 year ago
  • Allow twig 1
    By notFloran, 1 year ago
  • Remove warning
    By notFloran, 1 year ago
  • Update README
    By notFloran, 1 year ago
  • change formating of twig to better reading
    By notFloran, 1 year ago
  • Use ExecutableFinder to find mjml
    By notFloran, 1 year ago
  • Remove typo
    By notFloran, 1 year ago
  • add twig integration
    By notFloran, 1 year ago
  • Remove integration of twig (for now)
    By notFloran, 1 year ago
  • Rename service
    By notFloran, 1 year ago
  • Add mimify
    By notFloran, 1 year ago
  • add warning
    By notFloran, 1 year ago
  • add error handling
    By notFloran, 1 year ago
  • add check of process execution
    By notFloran, 1 year ago
  • Add symfony process
    By notFloran, 1 year ago
  • Fix link in README
    By notFloran, 1 year ago
  • Fix mailer in README
    By notFloran, 1 year ago
  • Better README
    By notFloran, 1 year ago
  • Update README
    By notFloran, 1 year ago