php - How to embed stylesheets with Assetic based on a value in the session -
i want embed different stylesheet files assetic in twig template of symfony2 project. used stylesheet depends on theme setting of user.
i used
{% stylesheets '@cuteflowcorebundle/resources/public/css/application.css' '@cuteflowcorebundle/resources/public/css/theme/'~app.session.get('cuteflow_theme')~'/application.css' %} <link rel="stylesheet" href="{{ asset_url }}" type="text/css" media="all" /> {% endstylesheets %}
but throws error:
unexpected token "operator" of value "~" in "corebundle::layout.html.twig"
i tried following too. didn't either.
{% set theme = '@cuteflowcorebundle/resources/public/css/theme/'~app.session.get('cuteflow_theme')~'/application.css' %} {% stylesheets '@cuteflowcorebundle/resources/public/css/application.css' theme %} <link rel="stylesheet" href="{{ asset_url }}" type="text/css" media="all" /> {% endstylesheets %}
any ideas how can done?
the answer simple : cannot it.
assetic iterate templates , generate every files {% stylesheets %}
blocks.
if use variable (session example), assetic cannot "guess" possible values.
you have 2 possibilities :
- separate 2 css calls (1 common call, 1 dedicated theme css) - makes more sense me
- create 1 css per theme
separate 2 css calls
{% stylesheets "a.css" "b.css" %} ... {% endstylesheets %} <link rel="stylesheet" href="{{ asset("css/" ~ theme ~ ".css") }}" />
create 1 css per theme
if want create 1 theme each available theme, keeping simple, have manually :
{% if theme == "xxx" %} {%stylesheets "a.css" "xxx.css" %} ... {% endstylesheets %} {% elseif theme == "yyy" %} {%stylesheets "a.css" "yyy.css" %} ... {% endstylesheets %} {% endif %}
Comments
Post a Comment