I've managed to get to the point where I understand how to move blocks from column to column in my Magento layouts: via specifying a "left" or "right" attribute in the <reference>
tag. However, I don't understand how to change the order in which blocks appear. I've noticed that the "before" and "after" attributes of the <block>
tag have something to do it with, but I'm not sure how they work. If I want to move a block from the top of its area to anywhere else in our page, what's the proper use and syntax for those attributes?
For example, I have a Category page and I have these blocks in it:
view.phtml
list.phtml
toolbar.phtml
... and so on.
I want to put my block anywhere within these blocks, or at the top of these blocks, or make all of these blocks show up inside another block. How can I use "before" and "after" to achieve this using my local.xml
file?
Note: I can do it manually by inheriting their respective .xml files, but that's not a good solution to the problem as a whole.
before
: Used to position the block before a block with the name specified in the value. If "-" value used the block is positioned before all other blocks of its level of block nesting.
after
: Used to position the block after a block with the name specified in the value. If "-" value used the block is positioned after all other blocks of its level of block nesting.
Updated: examples from some random core layout updates:
<reference name="right">
<block type="catalog/product_compare_sidebar" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>
</reference>
<reference name="right">
<block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>
</reference>
Updated: I believe before
and after
work only in core/text_list
and similar(descendant) blocks, i.e. blocks which just render blocks their nested blocks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With