我在Symfony 2.1.3中使用MopaBootstrapBundle和Twig模板。这个包有base.html.twig模板,其中包含脚本块:
{% block foot_script %}
{# To only use a subset or add more js overwrite and copy paste this block
To speed up page loads save a copy of jQuery in your project and override this block to include the correct path
Otherwise the regeneration is done on every load in dev more with use_controller: true
#}
{% javascripts
'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-transition.js'
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-modal.js'
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-dropdown.js'
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-scrollspy.js'
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-tab.js'
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-tooltip.js'
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-popover.js'
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-alert.js'
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-button.js'
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-collapse.js'
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-carousel.js'
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-typeahead.js'
'@MopaBootstrapBundle/Resources/public/js/mopabootstrap-collection.js'
'@MopaBootstrapBundle/Resources/public/js/mopabootstrap-subnav.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock foot_script %}
我正在使用以下方法在我的模板中扩展它:
{% extends 'MopaBootstrapBundle::base.html.twig' %}
{% block foot_script %}{% endblock foot_script %}
但它仍然尝试加载 Bundle 的base.html.twig模板,我得到:
在“MopaBootstrapBundle::base.html.twig”中编译模板(“无法找到文件“@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-transition.js”。”)期间引发了异常。
我发现,如果你像这样扩展它:
{% extends 'MopaBootstrapBundle::base.html.twig' %}
{% block foot_script %}
{% javascripts
'@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-typeahead.js'
'@MopaBootstrapBundle/Resources/public/js/mopabootstrap-collection.js'
'@MopaBootstrapBundle/Resources/public/js/mopabootstrap-subnav.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock foot_script %}
注意typeahead.js
我得到:
编译“MopaBootstrapBundle::base.html.twig”中的模板(“无法找到文件“@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-typeahead.js”。”)时引发异常。
如果我只删除一行:
{% extends 'MopaBootstrapBundle::base.html.twig' %}
{% block foot_script %}
{% javascripts
'@MopaBootstrapBundle/Resources/public/js/mopabootstrap-collection.js'
'@MopaBootstrapBundle/Resources/public/js/mopabootstrap-subnav.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock foot_script %}
我得到:
在“MopaBootstrapBundle::base.html.twig”中编译模板(“无法找到文件“@MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-transition.js”。”)期间引发了异常。
它仍然尝试从基本模板加载所有脚本。
任何建议如何覆盖 *foot_script* 块以使其为空而不加载这些 JS 文件?