I work a multi-localization project using Symfony2 , and i separate ( CSS/Images ) on different folder based on current user local.
Folder Structure Ex:
Resources\
public\
css\
ar\
home.css
en\
home.css
**Now i need the Assetic to render the correct home.CSS file based on current user local {ar | en} without loosing twig and filters functionality **
Example - This not work :
{% stylesheets
'bundles/atcopcore/css/{ app.request.locale }/home.css' filter='cssrewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
Note : I want to get advantage of css compine and this can't be done if i do the following :
<link rel="stylesheet" href="{{ asset('css/' ~ app.request.locale ~ '/home.css') }}" />
How i can do this ...
i found a link could be usefull , but i think there is more professional way to do this.
How to embed stylesheets with Assetic based on a value in the session
Please , Any suggestions ?
Assetic provides an functionality for you problem.
Add this to your configuration
assetic:
# more from assetic
variables:
locale: [de, en, it, es] # whatever
And in your twig file:
{% stylesheets filter='cssrewrite' 'bundles/atcopcore/css/home.{locale}.css' %}
{% endstylesheets %}
<link href="{{ asset('bundles/atcopcore/css/home.' ~ app.request.locale ~ '.css') }}" rel="stylsheet" />
Now assetic will create 4 files, home.de.css, home.en.css, home.it.css and home.es.css. And in your template your decide which css should be loaded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With