views:

37

answers:

2

I have created a module with several different controllers and therefore different pages.

I want to have a default sidebar on each of my own pages but not the rest of the site.

when i use the <default></default> it obviously propogates throughout the entire site.

When i try <mymodule_default></mymodule_default> nothing happens.

I am therefore left with having to copy and paste my whole layout for each seperate page of my module.

Is there any way in magento layouts to specify only once, some xml that is to be shared by each page that belongs to a module?

+2  A: 

Sure, this is definitely possible. When you load a layout using loadLayout, there are implicit arguments to the function, even though it is typically called sans arguments. The loadLayout function will actually take one or more strings for layouts to load by default. Which means that you can do this:

$this->loadLayout(array('default', 'your_layout_handle'));

Define a layout for that handle like so:

<layout>
    <your_layout_handle>
        <reference name="left">
             <block type="yourmodule/yourblock" />
        </reference>
    </your_layout_handle>
</layout>

Hope that helps!

Thanks, Joe

Joseph Mastey
Great! This seems to have worked. I must admit, alot of magento seems like voodoo at the moment. Its so poorly documented and it is taking a long time to do very simple things. Im beginning to think it has been the wrong decision to move to magento for ecommerce development.
David
+1  A: 

For each layout section that relates to one of your pages add an update reference.

<mymodule_page_index>
    <update handle="mymodule_default"/>
</mymodule_page_index>

The same thing is used for customer account pages in customer.xml.

clockworkgeek