Git Product home page Git Product logo

toinlinestyleemailbundle's Introduction

ToInlineStyleEmailBundle

ToInlineStyleEmailBundle is a Symfony2 bundle to use the CssToInlineStyles translator by Tijs Verkoyen (see https://github.com/tijsverkoyen/CssToInlineStyles for the repository)

Requirements

ToInlineStyleEmailBundle is only supported on PHP 5.3.3 and up.

Installation

Please, use the Composer to install this bundle in your Symfony2 app.

The following lines should be added in your composer.json

"require": {
    "robertotru/to-inline-style-email-bundle": "dev-master"
},

Then, register the bundle in your AppKernel by adding the following line:

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.:

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.

$converter = $this->get('css_to_inline_email_converter');
 
$html = ...; // get the HTML here
$css = ....; // get the CSS here
      
$converter->setHTML($html);
$converter->setCSS($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:

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.:

$converter->setHTMLByView('AcmeTestBundle:MyController:my_template.html.twig', 
   array('param_1'=>$val_of_param_1, ..., 'param_n'=>$val_of_param_n));

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

You can use inline css directly in Twig template:

{% inlinecss '/css/email.css' %}
<div class="foo">
...
</div>
{% endinlinecss %}

Paths relative to bundle are supported as well:

{% inlinecss '@AcmeBundle:css:email.css' %}
<div class="foo">
...
</div>
{% endinlinecss %}

Read the docs in the files for further details on the usage of the service.

Contributing

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

About the author of the bundle

ToInlineStyleEmailBundle has been originally developed by Roberto Trunfio. Currently, the bundle is mantained by Daniel Richter.

toinlinestyleemailbundle's People

Contributors

cordoval avatar crussell52 avatar khasinski avatar mente avatar paulandrieux avatar richtermeister avatar robertotru avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.