通过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>
此Layout 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
为空 ,则会将该块添加到 -
alias
是您的块的别名,如果为空,将使用块的名称.
siblingName
之后或子代列表的底部.
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屋!