问题描述
我会保持这个简单....在我的产品页面上我需要删除prototype.js文件并将其替换为最新版本的原型。到目前为止,使用local.xml我已成功使用此替换它:
I'll keep this simple.... on my product pages I need to remove the prototype.js file and replace it with the latest version of prototype. So far using local.xml I have successfully replaced it using this:
<action method="removeItem"><type>js</type><name>prototype/prototype.js</name></action>
<action method="addJs"><script>prototype/prototype-new.js</script></action>
现在的问题是现在原型被加载到其他所有包含停止工作的包含之下。
The issue is that now prototype is loaded below everything other includes which stops it working.
有没有办法使用local.xml设置JavaScript的顺序,而不必再删除和添加每个文件?
Is there a way of setting the order of a JavaScript include using local.xml without having to remove and add every single file again?
推荐答案
你可以使用params元素,其中包含data-groupHTML属性,Magento会在没有任何项目之后设置params设置的项目paramsset。您可以在主题中使用local.xml以确保这些元素的顺序(我建议让Magento首先添加其标准文件):
You can use the params element, with "data-group" HTML attribute in it, Magento will put items with "params" set after any items with no "params" set. You can use local.xml in your theme to ensure the order of these elements (I recommend to let Magento add its standard files first):
<action method="addJs">
<script>prototype/javascript0.js</script>
<params><![CDATA[data-group="js002"]]></params>
<!-- creates first group js002 -->
</action>
<action method="addJs">
<script>prototype/javascript1.js</script>
<params><![CDATA[data-group="js002"]]></params>
<!-- appends to created group js002, after javascript0 -->
</action>
<action method="addJs">
<script>prototype/javascript2.js</script>
<params><![CDATA[data-group="js001"]]></params>
<!-- creates first group js001 -->
</action>
<action method="addJs">
<script>prototype/javascript3.js</script>
<params><![CDATA[data-group="js001"]]></params>
<!-- appends to created group js001, after javascript2 -->
</action>
<action method="addJs">
<script>prototype/javascript4.js</script>
<params><![CDATA[data-group="js002"]]></params>
<!-- appends to created group js002, after javascript1 -->
</action>
<action method="addJs">
<script>prototype/javascript5.js</script>
<!-- no params supplied, will be rendered before any groups -->
</action>
设置params的元素的顺序仅由动作的顺序决定执行。项目按params的值进行分组,因此一旦第一个动作(javascript2.js)定义了组js001,具有相同组名的连续动作将附加到该组等。
The order in which elements with "params" set are rendered in only determined by the order in which actions are executed. Items are rendered grouped by the value of "params", so once group "js001" is defined by the first action (javascript2.js), successive actions with the same group name will append to that group, etc.
在上面的例子中,渲染的顺序是:
In the example above, the order of rendering will be:
- prototype / javascript5.js(没有参数,首先出现)
- prototype / javascript0.js(首次创建的params组js002)
- prototype / javascript1.js(首次创建) params groupjs002)
- prototype / javascript4.js(首次创建的params组js002)
- prototype / javascript2.js(第二次创建) params groupjs001)
- prototype / javascript3.js(第二个创建的params组js001)
- prototype/javascript5.js (no params, comes first)
- prototype/javascript0.js (first created params group "js002")
- prototype/javascript1.js (first created params group "js002")
- prototype/javascript4.js (first created params group "js002")
- prototype/javascript2.js (second created params group "js001")
- prototype/javascript3.js (second created params group "js001")
使用addItem addJs,addCss等添加的项目以相同的方式进行威胁,但是它们有所不同(并且将相应地进行超级分组)类型(请参阅下面的顺序),每个组都在内部订购超级组如上所述:
Items added using addItem addJs, addCss, etc, are threated in the same way, however they differ (and will be super-grouped accordingly) by type (see order below), with each group in super-groups internally ordered as explained above:
- js
- skin_js
- js_css
- skin_css
- js
- skin_js
- js_css
- skin_css
这篇关于重新排序Magento JavaScript包含(addJs)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!