views:

35

answers:

3

I'm doing a custom module in Magento and everything is going swimmingly... except I want to change the base layout template that all pages in the module use. I've done some googling with little success. Anyone have any answers? I want to do something along the lines of:

...
<optionbox>
  <reference name="root">
    <action method="setTemplate"><template>page/empty.phtml</template></action>
  </reference>
</optionbox>

As you may guess, it's a lightbox... I'm a glutton for punishment I guess :)

A: 

In my modules I do it within the controller action like so:

public function listAction() {
  $this->loadLayout();
  $this->getLayout()->getBlock('root')->setTemplate('page/2columns-right.phtml');
  $this->renderLayout();
}
silvo
Do you have to do this for every action?
Joe Mills
It seems so. I tried doing it in the layout xml file but it did not work for me. This way is more flexible because you can customise it depending on pretty much every parameter at runtime...
silvo
A: 

have you tried inserting that snippet into your optionbox.xml layout file? It looks like it should work as you have it?

Jonathan Day
Unfortunately it does not. I'm not sure what I'm doing wrong there...
Joe Mills
Hmm... Adding another answer so I can format it...
Jonathan Day
+1  A: 

I notice that you've got the root of your layout update as <optionbox> which in theory should cover all controllers and actions under that module. However, I've only ever seen this done with <optionbox_index> where index is from IndexController in your module. So perhaps try this replaced with your controller name:

<layout>
 ...
 <optionbox_index>
   <reference name="root">
     <action method="setTemplate"><template>page/empty.phtml</template></action>
   </reference>
 </optionbox_index>

Also, you should try Alan Storm's LayoutViewer module, instructions on it's use here. That might help you debug it.

Cheers, JD

Jonathan Day
Based on all the heartache and suffering I've been through trying to get this to work I'd agree. I think that a controller is required to set a design override, at least at this level. That's basically what I'm doing now. Thanks for the answer.
Joe Mills