generalmedia/twigemailrenderbundle

Rendering email using Twig

v3.0.1 2018-02-06 13:34 UTC

This package is auto-updated.

Last update: 2020-08-01 12:44:30 UTC


README

Build Status

TwigEmailRenderBundle renders twig templates as emails. You can define multiple block in your template, each block will be added to your email as a different part (object,body,text).

Changelog

3.0.1

  • Changes dependencies for twig v2

3.0.0

  • Drop support for PHP 5.5 + Add test for PHP 7.0 + 7.1

2.0.1

  • Fix hasBlock detection with parent templates.

2.0.0 DO NOT USE

  • Support global variables
  • Add option 'strict_variables'

Installation

Install the latest version with

$ composer require generalmedia/twigemailrenderbundle

You can also add this to your composer.json and run composer update

  "require": {
	"generalmedia/twigemailrenderbundle" : "~3.0.0"
   },

Add this to you AppKernel:

new Generalmedia\TwigEmailRenderBundle\TwigEmailRenderBundle(),

Note: Use ~2.0 for php 5.5.

Usage

Render email like twig views:

$msg = $this->get("generalmedia_email_render_twig")->getMessage("MyTemplate.email.twig");
$msg->setTo("...@...");
$this->get("mailer")->send($msg);

Your template is rendered with 3 blocks:

  • Block subject: Your email subject
  • Block text : Your email text
  • Block html: Your email html.

Subject is mandatory, and you must define at least one of theses blocks: text, html.

Configuration

All theses block names can be configured as follow:

twig_email_render:
  blocks:
    subject: 'email_subject'
    text: 'email_text'
    html: 'email_html'

Author

Laurent Constantin for Generalmedia SA.

Contact info@generalmedia.ch if needed.

License

TwigEmailRenderBundle is licensed under the MIT License - see the LICENSE file for details