Magento – XML Block Layout

blockslayoutxml

I am trying to show newsletter block in the footer, except for the Homepage where I want to show it only in content area.

I used local.xml to move newsletter from left to footer:

<reference name="left">
   <remove name="left.newsletter"/><!-- Moved newsletter to the footer -->
</reference>

Then:

<reference name="footer">
    <!-- Move newsletter to the footer -->
    <block type="newsletter/subscribe" name="newsletter" as="newsletter" template="newsletter/subscribe.phtml"/>
</reference>

Easy, we have it in the footer. My problem is when showing it in homepage content. I used:

<cms_index_index>
    <reference name="content">
        <block type="newsletter/subscribe" name="my.newsletter" as="my.newsletter" template="newsletter/subscribe.phtml" before="-">
            <action method="setElementClass">
                <value>someclass</value>
            </action>
        </block>
    </reference>      
</cms_index_index>

This shows fine the block in content area. However to remove newsletter in the homepage footer I used within CMS page, design, layout update:

<reference name="footer">
    <remove name="newsletter"/>
</reference>

And also tried adding it in local.xml under cms_index_index

But it either shows twice in homepage (content and footer) or only in content, and not showing in any other page (in footer).

Is it related with caching? Am I using it wrong?

Best Answer

You could do this without calling remove and then having to recreate each block. Simply use the unsetChild and insert actions, they will allow you to move blocks around. The following xml should give you your desired results.

<default>
    <reference name="left">
        <action method="unsetChild">
            <name>left.newsletter</name>
        </action>
    </reference>
    <reference name="footer">
        <action method="insert">
            <block>left.newsletter</block>
        </action>
    </reference>
</default>
<cms_index_index>
    <reference name="footer">
        <action method="unsetChild">
            <name>left.newsletter</name>
        </action>
    </reference>
    <reference name="content">
        <action method="insert">
            <block>left.newsletter</block>
        </action>
    </reference>
</cms_index_index>