gushphp / ToInlineStyleEmailBundle

A Symfony2 bundle to use the CssToInlineStyles converter by Tijs Verkoyen
MIT License
59 stars 34 forks source link

Relative paths do not work #19

Closed khasinski closed 7 years ago

khasinski commented 9 years ago

I've tried current master with

{% inlinecss "@BadgeBundle:css:email.css" %}

And unfortunately it looks for the css in a directory starting with web/@BadgeBundle

cordoval commented 9 years ago

bump @Richtermeister

jaikdean commented 8 years ago

Same issue here.

jaikdean commented 8 years ago

I managed to get this working in Symfony 3.0 by using the following.

Template: {% inlinecss 'AppBundle:css:email.css.twig' %}

File location: src/AppBundle/Resources/views/css/email.css.twig

The syntax for referencing resources in bundle changed in Symfony at some point, and the documentation appears to use the old version. From what I could see, the filename must contain two . characters (eg. email.css would not work) and the leading @ should be dropped.

If the file can't be located for whatever reason, the code in this bundle reverts to trying to use whatever you specified as a path under the web/ directory.

jaikdean commented 8 years ago

This behaviour is due to the bundle using the templating.name_parser service (Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser by default) to resolve file locations. Since the file located isn't parsed/processed by Twig (i.e. it's not included as a template) this doesn't make sense. This name parser should really be removed and we should just rely on Kernel::locateResource() to locate the file, which would use the format as documented.

Looking at the history, it used to work in the way I've described, but was changed to the current (broken) behaviour by df0cf5c (part of https://github.com/robertotru/ToInlineStyleEmailBundle/pull/9). That commit explicitly made this (and only this) change.