Change order of blocks via local.xml file

前端 未结 3 1641
生来不讨喜
生来不讨喜 2020-12-04 08:52

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

相关标签:
3条回答
  • 2020-12-04 09:15

    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 example
    • siblingName 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 to 1, then the block will be added after siblingName or in the bottom of the children list if siblingName is empty
    • alias 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!

    0 讨论(0)
  • 2020-12-04 09:29

    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>
    
    0 讨论(0)
  • 2020-12-04 09:31

    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.

    0 讨论(0)
提交回复
热议问题