我正在开发一个包含主题系统的 symfony2 项目。由于该系统的限制,我必须在包含文件中定义 javascripts 和样式表块,然后将其包含在主题的布局树枝文件中。结构如下:
应用程序/资源/主题/{theme_name}/views/layout.html.twig
... code ...
{% include '::theme_assets.html.twig; %}
应用程序/资源/视图/theme_assets.html.twig
{% block stylesheets %}
{% stylesheets
'stylesheet.css'
'stylesheet2.css'
filter='cssrewrite'
output='css/packed/layout_theme.css'
%}
<link type="text/css" rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
{% block javascripts%}
{# same as stylesheets #}
{% endblock %}
然后,我希望能够在上面在各个页面上设置的初始块中包含其他 css/js 文件,例如
src/Blah/BlahBundle/Resources/views/subpage.html.twig
{% extends 'BlahBundle::layout.html.twig' %} {# the theme system works out that there is a theme overrde for this file #}
{% block body %}
...body...
{% endblock %}
{% block stylesheets %}
{{ parent() }} {# should include the initial block #}
<link rel="stylesheet" type="text/css" href="{{ asset('/bundles/blah/css/additional1.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ asset('/bundles/blah/css/additional2.css') }}" />
{% endblock %}
由于某种原因,当我查看“subpage.html.twig”时,这些额外的样式表不包括在内。我高度怀疑问题出在我的实施中,但我不确定我可以尝试什么!