gpt4 book ai didi

symfony - 如何使用条件 if 进入 assetic

转载 作者:行者123 更新时间:2023-12-02 10:49:27 29 4
gpt4 key购买 nike

我有一个 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]-->

我想知道如何在该 assetic 中使用此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 %}

最佳答案

如果您只想使用这个if,您可以将此代码放入 block 中:

{% 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 %}

关于symfony - 如何使用条件 if 进入 assetic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28369786/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com