Search code examples
phpmagentomagento-layout-xml

Magento, default layout for the custom module


I want to add a block in left column of only my module, not whole website.

If I place it in <default> tag it will be shown in whole website, but I want to do something like <mymodule_default>, is it possible?

I know I can place my block in every layout_handler like:

 <mymodule_controllername_actionname>
    <reference name="left">
        <block type="mymodule/block" name="left_navigation" before="-" template="mymodule/left-nav.phtml" />
    </reference>
 </mymodule_controllername_actionname>

but this is not what I want, I want to do it as:

 <mymodule_default>
    <reference name="left">
        <block type="mymodule/block" name="left_navigation" before="-" template="mymodule/left-nav.phtml" />
    </reference>
 </mymodule_default>

Or is it not preferable?

Thanks


Solution

  • Got an answer on another website, copying it here :

    You can only add layout update handle in each controller

    public function preDispatch()
    {
      parent::preDispatch();
      $this->getLayout()->getUpdate()
           ->addHandle('mymodule_default');
    }
    

    Or with instruction <update handle="mymodule_default"/> in all <mymodule_controllername_actionname> handles

    Example:

    <mymodule_controllername_actionname>
        <update handle="mymodule_default"/>
        ...
    <mymodule_controllername_actionname>