Is it possible to change the order of already existing blocks via the local.xml file? I know开发者_如何学C 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>
This Layout XML instruction does what you want. Look at this short reference of parameters for insert
method:
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.
Some Examples:
Move cart sidebar block after recently viewed products
<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>
Move cart sidebar block before recently viewed products
<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>
Move cart sidebar block at the end of the right block
<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>
Move cart sidebar block at the top of the left block
<reference name="right">
<action method="unsetChild">
<alias>cart_sidebar</alias>
</action>
</reference>
<reference name="left">
<action method="insert">
<blockName>cart_sidebar</blockName>
</action>
</reference>
Enjoy working with Magento!
You can remove previous layered navigation block and add a new layered navigation block after newsletter block.
<reference name="left">
<remove name="catalog.leftnav" />
<block type="catalog/layer_view" name="catalog.leftnavcustom" after="left.newsletter" template="catalog/layer/view.phtml"/>
</reference>
Note that I use a custom name for the new block.
The accepted answer didn't work for me (EE1.14) but something close to it, this:
<wishlist_index_index>
<reference name="customer.wishlist.items">
<action method="unsetChild">
<name>customer.wishlist.price</name>
</action>
<action method="insert">
<blockName>customer.wishlist.price</blockName>
<after>customer.wishlist.qty</after>
</action>
</reference>
</wishlist_index_index>
精彩评论