如何使用条件进入资产

时间:2015-02-06 16:01:30

标签: symfony assetic

我有一个html模板,其中包含条件 - >

的代码
<!--[if !IE]> -->

    <script type="text/javascript">
        window.jQuery || document.write("<script src='assets/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
    </script>

    <!-- <![endif]-->

    <!--[if IE]>
   <script type="text/javascript">
        window.jQuery || document.write("<script src='assets/js/jquery-1.10.2.min.js'>"+"<"+"/script>");
   </script>
   <![endif]-->

我想知道如何将 if 用于此资产

{% block Javascript %}
    {% javascripts output='js/dashboard/main.js' filter='?yui_js'
    'dashboard/js/date-time/bootstrap-datepicker.min.js'
    %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}
{% endblock %}

1 个答案:

答案 0 :(得分:3)

如果您只想使用 if ,您可以将此代码置于阻止中:

{% block Javascript %}
    <!--[if !IE]> -->

    <script type="text/javascript">
        window.jQuery || document.write("<script src='assets/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
    </script>

    <!-- <![endif]-->

    <!--[if IE]>
   <script type="text/javascript">
        window.jQuery || document.write("<script src='assets/js/jquery-1.10.2.min.js'>"+"<"+"/script>");
   </script>
   <![endif]-->
    {% javascripts output='js/dashboard/main.js' filter='?yui_js'
    'dashboard/js/date-time/bootstrap-datepicker.min.js'
    %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}
{% endblock %}

如果您想将jquery.min.js与其他脚本编译成一个文件,您需要这样的内容:

{% block Javascript %}
    <!--[if !IE]> -->
    {% javascripts output='js/dashboard/main.js' filter='?yui_js'
    'dashboard/js/date-time/bootstrap-datepicker.min.js'
    'assets/js/jquery-2.0.3.min.js'
    %}
    <script type="text/javascript">
        window.jQuery || document.write("<script src='{{ asset_url }}'>"+"<"+"/script>");
    </script>
    {% endjavascripts %}

    <!-- <![endif]-->

    <!--[if IE]>
    {% javascripts output='js/dashboard/main-ie.js' filter='?yui_js'
    'dashboard/js/date-time/bootstrap-datepicker.min.js'
    'assets/js/jquery-1.10.2.min.js'
    %}
    <script type="text/javascript">
        window.jQuery || document.write("<script src='{{ asset_url }}'>"+"<"+"/script>");
    </script>
    {% endjavascripts %}
   <![endif]-->

{% endblock %}