我想在Symfony2项目的twig模板中嵌入带有资产的不同样式表文件.使用的样式表取决于用户的主题设置.
我用了
{% 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 %}
Run Code Online (Sandbox Code Playgroud)
但这会引发错误:
Unexpected token "operator" of value "~" in "CoreBundle::layout.html.twig"
Run Code Online (Sandbox Code Playgroud)
我也试过以下.但这也没有帮助.
{% 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 %}
Run Code Online (Sandbox Code Playgroud)
有什么想法可以做到这一点?