Question

I had fun to create some small scenario in layout and I don't understand some thing.

In the layout, would it be possible to remove a block and then create it again ?

I explain: assuming that I want to remove the header so i add <remove name="header"/> in local.xml good the block is removed, now I recreate it again by adding the xml code bellow but it doesn't work. The second block is quite correct because if i delete <remove name="header"/> i will have two headers.

The xml who creates the header:

<block type="page/html_header" name="header" as="header">
     <block type="page/template_links" name="top.links" as="topLinks"/>
     <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
     <block type="core/text_list" name="top.menu" as="topMenu" translate="label">
           <label>Navigation Bar</label>
           <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/>
     </block>
     <block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
           <label>Page Header</label>
           <action method="setElementClass"><value>top-container</value></action>
     </block>
     <block type="page/html_welcome" name="welcome" as="welcome"/>
</block>
Was it helpful?

Solution

The key here is in the order that Magento processes the layout files. Essentially it combines all the layout files into one XML document. This means the new XML will have two "header" blocks. Then it runs through special tags like updates and actions since they may alter the xml. Then it processes all the remove tags and then proceeds to create the views as defined by the final XML document after this "preprocessing" of instructions.

So the remove element will remove all references to any element with that name attribute value, even if your intention was to replace it later. What you should do instead is to either use a different name, like theme_header; or, individually use the unsetChild action to remove those elements you don't want in the header.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top