ToInlineStyleEmailBundle
ToInlineStyleEmailBundle is a Symfony2 bundle to use the CssToInlineStyles translator by _Tijs Verkoyen_ (see
https://github.com/tijsverkoyen/CssToInlineStyles for the original repository), (*1)
Requirements
ToInlineStyleEmailBundle is only supported on PHP 5.3.3 and up., (*2)
Installation
Please, use the Composer to install this bundle in your Symfony2 app., (*3)
The following lines should be added in your composer.json
, (*4)
"require": {
"robertotru/to-inline-style-email-bundle": "dev-master"
},
Then, register the bundle in your AppKernel by adding the following line:, (*5)
``` php
new JoshTaylor\ToInlineStyleEmailBundle\JoshTaylorToInlineStyleEmailBundle(),, (*6)
Documentation and Examples
===========
The bundle provides a service named **css_to_inline_email_converter**. Use it in a controller to have a nice shortcut to the
converter developed by _Tijs Verkoyen_. E.g.:
``` php
public function indexAction() {
$converter = $this->get('css_to_inline_email_converter');
...
}
Get the HTML and the CSS as a string and set this required values to the converter object, e.g., (*7)
``` php
$converter = $this->get('css_to_inline_email_converter');, (*8)
$html = ...; // get the HTML here
$css = ....; // get the CSS here, (*9)
$converter->setHTML($html);
$converter->setCSS($css);, (*10)
The retrieval of the HTML and CSS files from its folder it is only up-to you. E.g. in your controller retrieve the content of your CSS as:
``` php
file_get_contents($this->container->getParameter('kernel.root_dir').
'/../src/Acme/TestBundle/Resources/css/mystyle.css');
Of course, it is supposed that a Symfony user will use a template instead of a static HTML page. Hence,
for convenience, the service provides a function capable to render a template. E.g.:, (*11)
``` php
$converter->setHTMLByView('AcmeTestBundle:MyController:my_template.html.twig',
array('param_1'=>$val_of_param_1, ..., 'param_n'=>$val_of_param_n));, (*12)
The preceding function must be used _in vece_ of function ```setHTML()```.
You can use inline css directly in Twig template:
``` html
{% inlinecss '/css/email.css' %}
<div class="foo">
...
</div>
{% endinlinecss }
Paths relative to bundle are supported as well:, (*13)
html
{% inlinecss '@AcmeBundle:css:email.css' %}
<div class="foo">
...
</div>
{% endinlinecss }
, (*14)
Read the docs in the files for further details on the usage of the service., (*15)
Contributing
ToInlineStyleEmailBundle is an open source project. Contributions are encouraged.
Feel free to contribute to improve this bundle., (*16)
About the author of the bundle
ToInlineStyleEmailBundle has been originally developed and is maintained by Roberto Trunfio (see more on the author at www.trunfio.it), (*17)
This unofficial branch is maintained by Josh Taylor until fixes are pushed upstream by the original author., (*18)