Search code examples
magentolayoutadminhtml

Displaying my Bloc in mutiple "zone"?


I am working on a Slider extension for Magento, I want to be able to display my slider in one of this positions : top_left, top_right, top_center, bottom_left/right/center ! and be able to choose this position from my Admin backend whith a DropList or somthing like. Can you help please :) ! Thanks


Solution

  • The best solution i found is to add an Observer with this event :

    controller_action_layout_load_before

    Then we load the layout in it :

    public function addBlock(Varien_Event_Observer $observer)
    {
       $layout = $observer->getEvent()->getLayout()->getUpdate();
       $layout->addHandle(ThePositionYouWant);
       return $this;
    }
    

    In your Layout put he different position you want :

    <position_name>
        <reference name="content">
            <block type="BlockName" name="Name" before="-" template="YourBlockTemplate"/>
         </reference>
    </position_name>
    
        <position_name2>
            <reference name="left">
                <block type="BlockName" name="Name" after="-" template="YourBlockTemplate"/>
             </reference>
        </position_name2>
    

    And it Works. Hope this will help :) !