Magento 1.9 – Fix Static Block Loading in Wrong Order

layoutmagento-1.9static-blockxml

I've added my code to cms.xml to display static blocks in the footer. I want them to be in the following order:

  • Left
  • Middle
  • Right

But when I check my site, they're loaded in this order:

  • Right
  • Left
  • Middle

Here is the code I use to display the blocks

<reference name="footer">
        <block type="cms/block" name="cms_footer_links" before="footer_links">
            <action method="setBlockId"><block_id>footer_links</block_id></action>
        </block>

       <block type="cms/block" name="cms_footer_middle" before="footer_middle">
            <action method="setBlockId"><block_id>footer_middle</block_id></action>
        </block>

        <block type="cms/block" name="cms_footer_right" before="footer_right">
            <action method="setBlockId"><block_id>footer_right</block_id></action>
        </block>
 </reference>

Can anybody tell me what i'm doing wrong?

Best Answer

I see that you have before attributes in your layout.
The value of before should not be the static block id. It should be the block type="cms/block" name.
But if you want to add them in that order you should use after instead of before. Both of them work, but it's more readable using after

<reference name="footer">
    <block type="cms/block" name="cms_footer_links"><!-- this does not need after-->
        <action method="setBlockId"><block_id>footer_links</block_id></action>
    </block>

   <block type="cms/block" name="cms_footer_middle" after="cms_footer_links"><!-- placed after `cms_footer_links` -->
        <action method="setBlockId"><block_id>footer_middle</block_id></action>
    </block>

    <block type="cms/block" name="cms_footer_right" after="cms_footer_middle"><!-- placed after `cms_footer_middle` -->
        <action method="setBlockId"><block_id>footer_right</block_id></action>
    </block>
 </reference>
Related Topic