通过 local.xml 文件更改块的顺序 [英] Change order of blocks via local.xml file
问题描述
是否可以通过 local.xml 文件更改现有块的顺序?我知道您可以使用 after 或 before 属性更改块的顺序,但是如何更改现有块的这些属性.
Is it possible to change the order of already existing blocks via the local.xml file? I know you can change the order of a block with the after or before attribute, but how can one change those attributes of existing blocks.
例如,如果我想将分层导航块放在左栏中的时事通讯订阅块下方,我该怎么做?
For example, if I want to place the layered navigation block underneath the newsletter subscription block in the left column, how would I do that?
推荐答案
你需要执行一个小技巧,移除子块并将其添加到新位置:
You need to perform a small trick, remove child block and add it in new position:
<reference name="parent.block.name">
<action method="unsetChild">
<alias>child_block_alias</alias>
</action>
<action method="insert">
<blockName>child.block.name</blockName>
<siblingName>name_of_block</siblingName>
<after>1</after>
<alias>child_block_alias</alias>
</action>
</reference>
此布局 XML 指令可以满足您的需求.看看这个 insert
方法参数的简短参考:
This Layout XML instruction does what you want. Look at this short reference of parameters for insert
method:
blockName
是您在整个布局中的块唯一名称,例如product.view
siblingName
是块的唯一名称,它已经存在于插入目标块中,用于定位您的块.留空以在顶部或底部显示.after
是块位置的布尔标识符.如果等于1
,则在siblingName
之后添加block,如果siblingName
为空,则添加到子列表的底部alias
是你的块的别名,如果它为空,将使用块的名称.
blockName
is your block unique name across the layout,product.view
for examplesiblingName
is an block unique name, that is already exists in insertion target block, used for positioning of your block. Leave empty to display it at the top or at the bottom.after
is a boolean identifier of block position. If equals to1
, then the block will be added aftersiblingName
or in the bottom of the children list ifsiblingName
is emptyalias
is the alias of your block, if it is empty the name of block will be used.
一些例子:
在最近查看过的产品后移动购物车侧边栏
<reference name="right">
<action method="unsetChild">
<alias>cart_sidebar</alias>
</action>
<action method="insert">
<blockName>cart_sidebar</blockName>
<siblingName>right.reports.product.viewed</siblingName>
<after>1</after>
</action>
</reference>
在最近查看的产品之前移动购物车侧边栏
<reference name="right">
<action method="unsetChild">
<alias>cart_sidebar</alias>
</action>
<action method="insert">
<blockName>cart_sidebar</blockName>
<siblingName>right.reports.product.viewed</siblingName>
<after>0</after>
</action>
</reference>
移动右侧块末尾的购物车侧边栏块
<reference name="right">
<action method="unsetChild">
<alias>cart_sidebar</alias>
</action>
<action method="insert">
<blockName>cart_sidebar</blockName>
<siblingName></siblingName>
<after>1</after>
</action>
</reference>
移动左侧块顶部的购物车侧边栏块
<reference name="right">
<action method="unsetChild">
<alias>cart_sidebar</alias>
</action>
</reference>
<reference name="left">
<action method="insert">
<blockName>cart_sidebar</blockName>
</action>
</reference>
享受与 Magento 的合作!
Enjoy working with Magento!
这篇关于通过 local.xml 文件更改块的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!