php - Conditionally remove header/footer in Magento -


i have module page can accessed like

www.example.com/module/controller/action/id/10

i want in controller's action

$page = (int) mage::app()->getrequest()->getparam('id'); if($page == '12') {     $this->getlayout()->unsetblock('header');     $this->getlayout()->unsetblock('footer'); } 

but above method doesn't work, guess i'm passing wrong alias unsetblock method.

i know how hide header/footer via layout xml here want hide them in controller.

so searching alternative

<remove name="header"/> <remove name="footer"/>  

i found solution own question, sharing because may others.

1. create new layout handle page

// namespace/modulename/model/observer.php class namespace_modulename_model_observer extends mage_core_model_abstract {      public function addattributesethandle(varien_event_observer $observer)     {         $page = (int) mage::app()->getrequest()->getparam('id');         $handle = sprintf('modulename_controller_action_id_%s', $page);         $update = $observer->getevent()->getlayout()->getupdate();         $update->addhandle($handle);     } } 

2. enable observer in module's config.xml

// namespace/modulename/etc/config.xml <frontend>     <events>         <controller_action_layout_load_before>             <observers>                 <attributesethandle>                     <class>namespace_modulename_model_observer</class>                     <method>addattributesethandle</method>                 </attributesethandle>             </observers>         </controller_action_layout_load_before>     </events> </frontend> 

3. , change layout handle modulename_controller_action_id_12 in modules layout xml.

<modulename_controller_action_id_12>     <remove name="header"/>     <remove name="footer"/>     <reference name="root">         <action method="settemplate">             <template>page/1column.phtml</template>         </action>     </reference> </modulename_controller_action_id_12> 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -