2017 © Pedro PelĂĄez
 

symfony-bundle swift-twig

WeMakeCustom Bridge between SwiftMailer Twig

image

botnyx/swift-twig

WeMakeCustom Bridge between SwiftMailer Twig

  • Saturday, June 9, 2018
  • by botnyx
  • Repository
  • 0 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Swift-Twig mailer bridge.

This bundle provides an easy way to create email templates using Twig for the SwiftMailer library., (*1)

This helper is inspired from FOSUB TwigSwiftMailer., (*2)

If you're using FOS User Bundle, we also provide a mailer service drop-in replacement to support our additional features., (*3)

Installation

With Symfony

The best way to install this extension is through composer:, (*4)

First, require the bundle:, (*5)

composer require wemakecustom/swiftmailer-twig-bundle "^1.0"

Second, enable it:, (*6)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new WMC\SwiftmailerTwigBundle\WMCSwiftmailerTwigBundle(),
        // ...
    );
}

Third and finally, configure the web_directory parameter to use it:, (*7)

# config.yml

parameters:
    web_directory: %kernel.root_dir%/../web

and you're done., (*8)

FOS User Bundle integration

# config.yml

fos_user:
    service:
        mailer: wmc.swiftmailer_twig.fosub

With a pure Swiftmailer/Twig

The best way to install this extension is through composer:, (*9)

First, require the bundle:, (*10)

composer require wemakecustom/swiftmailer-twig-bundle "^1.0"

Then give the naming strategy to doctrine's configuration:, (*11)

<?php

$swiftMailerTemplateHelper = new \WMC\SwiftmailerTwigBundle\TwigSwiftHelper($twig, $web_directory);

Usage

It allows a Swift_Message to be populated with a Twig template. The template expects three blocks (subject, body_html, body_text). If any local image (i.e. whose src attribute starting with a single forward-slash /) with the class inline-image is found in the body_html block, it will be inlined in the email, allowing some eMail clients to render the image more easily., (*12)

This helper is available as the service wmc.swiftmailer_twig. To use it, invoke the method populateMessage with these three parameters:, (*13)

  1. the \Swift_Message
  2. template name
  3. data array for the template

The helper depends on Symfony's component DomCrawler, Twig and SwiftMailer., (*14)

Example:, (*15)


$data = []; // ... $data['recipient'] = ['name' => 'Jonh Smith', 'email' => 'recipient@example.com']; $message = $mailer->createMessage()->setTo(['recipient@example.com' => 'John Smith']); $swiftMailerTemplateHelper->populateMessage($message, 'AppBundle:Mail:my_email.mail.twig', $data); $mailer->send($message);
{# my_email.mail.twig #}

{% block subject -%}
   My email Subject
{%- endblock %}

{% block body_text %}
    Hello {{ recipient.name }},

    {# ... Awesome plain text email ... #}

    Best Regards,
    Keep being awesome!
{% endblock %}

{% block body_html %}


Hello {{ recipient.name }},

<p> {# ... Awesome HTML email ... #} </p> <p> Best Regards,<br /> <em>Keep being awesome!</em> </p> {% endblock %}

The Versions

09/06 2018

dev-master

9999999-dev

WeMakeCustom Bridge between SwiftMailer Twig

  Sources   Download

MIT

The Requires

 

by SĂ©bastin Lavoie

twig swiftmailer bridge fosub email templating

30/11 2017

v1.1

1.1.0.0

WeMakeCustom Bridge between SwiftMailer Twig

  Sources   Download

MIT

The Requires

 

by SĂ©bastin Lavoie

twig swiftmailer bridge fosub email templating

12/06 2017

v1.0.1

1.0.1.0

WeMakeCustom Bridge between SwiftMailer Twig

  Sources   Download

MIT

The Requires

 

by SĂ©bastin Lavoie

twig swiftmailer bridge fosub email templating

21/03 2016

v1.0

1.0.0.0

WeMakeCustom Bridge between SwiftMailer Twig

  Sources   Download

MIT

The Requires

 

by SĂ©bastin Lavoie

twig swiftmailer bridge fosub email templating