Load one js file using assetic inside Symfony2

落花浮王杯 提交于 2019-12-04 17:06:52
Nicolai Fröhlich

You can add a file to your assets like this:

{% javascripts
    '@YourBundle/Resources/public/js/*'
    '@AnotherBundle/Resources/public/js/some.js'
    '@YourBundle/Resources/public/vendor/someother.js'
    output="filename.js"
%}
    <script src="{{ asset_url }}"></script>
{% endjavascripts %}

In order to have pre-defined asset collections which you can then use as for example '@js_default' you can add these in your assetic.assets configuration as suggested in my answer here.

To add the contact.js after the main file js files you can do something like this.

    {% block javascripts %}
       {{- parent() -}}
       {% javascripts "@AcmeBundle/Resources/public/js/contact.js"  %} 
                 <script type="text/javascript" src="{{ asset_url }}" ></script>
       {% endjavascripts %}
    {% endblock %}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!