2017 © Pedro Peláez
 

symfony-bundle to-inline-style-email-bundle

A Symfony2 bundle for using the CssToInlineStyles translator by tijsverkoyen

image

gushphp/to-inline-style-email-bundle

A Symfony2 bundle for using the CssToInlineStyles translator by tijsverkoyen

  • Sunday, January 14, 2018
  • by cordoval
  • Repository
  • 4 Watchers
  • 53 Stars
  • 14,664 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 30 Forks
  • 2 Open issues
  • 7 Versions
  • 31 % Grown

The README.md

ToInlineStyleEmailBundle

ToInlineStyleEmailBundle is a Symfony2 bundle to use the CssToInlineStyles translator by _Tijs Verkoyen_ (see https://github.com/tijsverkoyen/CssToInlineStyles for the repository), (*1)

Requirements

ToInlineStyleEmailBundle is only supported on PHP 5.5 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)

``` json "require": { "gushphp/to-inline-style-email-bundle": "~1.4.0" },, (*5)


Then, register the bundle in your AppKernel by adding the following line: ``` php new RobertoTru\ToInlineStyleEmailBundle\RobertoTruToInlineStyleEmailBundle(),

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.:, (*6)

``` php public function indexAction() { $converter = $this->get('css_to_inline_email_converter'); ... }, (*7)


Get the HTML and the CSS as a string and set this required values to the converter object, e.g. ``` php $converter = $this->get('css_to_inline_email_converter'); $html = ...; // get the HTML here $css = ....; // get the CSS here return $converter->inlineCSS($html, $css);

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:, (*8)

``` php file_get_contents($this->container->getParameter('kernel.root_dir').'/../src/Acme/TestBundle/Resources/css/mystyle.css');, (*9)


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.: ``` php $converter->setHTMLByView( 'AcmeTestBundle:MyController:my_template.html.twig', [ 'param_1' => $val_of_param_1, // ..., 'param_n' => $val_of_param_n ] );

The preceding function must be used in vece of function setHTML()., (*10)

To use the generateStyledHTML method just use it like:, (*11)

``` php $converter->setHtml($html); $converter->setCss($css); return $converter->generateStyledHTML();, (*12)


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 '@AppBundle/Resources/css/email.css' %} , (*14)

...
{% endinlinecss %}
Dynamic variable is supported (Use absolute path with variable with asset or directly with full path to file)

``` html
{% set path = asset('css/email.css', null, true) %}
{% inlinecss path %}
<div class="foo">
...
</div>
{% endinlinecss %}

Dynamic variable is supported (Use absolute path with variable with asset or directly with full path to file), (*15)

html {% set path = asset('css/email.css', null, true) %} {% inlinecss path %} <div class="foo"> ... </div> {% endinlinecss %}, (*16)

Read the docs in the files for further details on the usage of the service., (*17)

Contributing

ToInlineStyleEmailBundle is an open source project, under MIT license. Contributions are encouraged. Feel free to contribute to improve this bundle., (*18)

About the author of the bundle

ToInlineStyleEmailBundle has been originally developed by Roberto Trunfio. Currently, the bundle is mantained by Luis Cordova via the gushphp organization., (*19)

The initial package on packagist robertotru was moved here to gushphp organization with the author consent for maintenance., (*20)

The Versions

14/01 2018

dev-master

9999999-dev http://github.com/gushphp/ToInlineStyleEmailBundle

A Symfony2 bundle for using the CssToInlineStyles translator by tijsverkoyen

  Sources   Download

MIT

The Requires

 

The Development Requires

email css inline style bundle symfony

14/01 2018

1.5.2

1.5.2.0 http://github.com/gushphp/ToInlineStyleEmailBundle

A Symfony2 bundle for using the CssToInlineStyles translator by tijsverkoyen

  Sources   Download

MIT

The Requires

 

The Development Requires

email css inline style bundle symfony

14/01 2018

1.5.1

1.5.1.0 http://github.com/gushphp/ToInlineStyleEmailBundle

A Symfony2 bundle for using the CssToInlineStyles translator by tijsverkoyen

  Sources   Download

MIT

The Requires

 

The Development Requires

email css inline style bundle symfony

04/12 2017

1.5.0

1.5.0.0 http://github.com/gushphp/ToInlineStyleEmailBundle

A Symfony2 bundle for using the CssToInlineStyles translator by tijsverkoyen

  Sources   Download

MIT

The Requires

 

The Development Requires

email css inline style bundle symfony

18/06 2017

1.4.0

1.4.0.0 http://github.com/gushphp/ToInlineStyleEmailBundle

A Symfony2 bundle for using the CssToInlineStyles translator by tijsverkoyen

  Sources   Download

MIT

The Requires

 

The Development Requires

email css inline style bundle symfony

01/06 2017

1.3.0

1.3.0.0 http://github.com/robertotru/ToInlineStyleEmailBundle

A Symfony2 bundle for using the CssToInlineStyles translator by tijsverkoyen

  Sources   Download

MIT

The Requires

 

email css inline style bundle symfony

21/01 2016

1.2

1.2.0.0 http://github.com/robertotru/ToInlineStyleEmailBundle

A Symfony2 bundle for using the CssToInlineStyles translator by tijsverkoyen

  Sources   Download

MIT

The Requires

 

email css inline style bundle symfony