dongshan6870 2014-03-28 18:27
浏览 44
已采纳

在Symfony2上包含多个资产的最佳方法

I' m usign the same amount of assets in my symfony2 project. If I upgrade a plugin version, all files must be modified. So, which is the best way to add assets on twig templates using Symfony2 framework?

{% block javascriptCodigo %}
    {{ parent() }}
    <script type="text/javascript" src="{{ asset('bundles/Bundle/js/ajaxLoadTables/ajaxLoadTables.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bundles/Bundle/js/jquery-loadmask/jquery.loadmask.min.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bundles/Bundle/js/jquery-validate/jquery.validate.min.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bundles/Bundle/js/jquery-validate/localization/messages_es.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bundles/Bundle/js/bootstrap3-dialog/js/bootstrap-dialog.min.js') }}"></script>
...
  • 写回答

1条回答 默认 最新

  • dony113407 2014-03-28 18:45
    关注

    The best way is to use AsseticBundle. All is described in details in doc.

    In general, while assetic is enabled you can do something like

    {% block javascripts %}
        {{ parent() }}
        {% javascripts
            '@AcmeDemoBundle/Resources/public/js/knockout.jquery-bindings.js'
            '@AcmeDemoBundle/Resources/public/js/jquery.validate.min.js'
            '@AcmeDemoBundle/Resources/public/js/jquery.validate.password.js'
        %}
        <script src="{{ asset_url }}"></script>
        {% endjavascripts %} 
    {% endblock %}
    

    This will combine all your assets to one file. You can also use this for stylesheets by using stylesheets function. There is also easy way to add version number for your query url (for asset) which will solve browser cache issues.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊