In some cases there is a need to remove Magento header or footer from pages, for example you are creating some custom landing page and you don’t want to put header or footer or want to remove both from that page, this tutorial will help you achieving it. Need help? You can Email me or Skype chat You have a module page that can be accessed like www.yoursite.com/module/controller/action/id/10 And you want to unset header and footer based on id parameter, for example you don’t want header and footer appear when id is 10. But you can’t unset header footer like above code. Fortunately, Magento’s layout engine is flexible enough to provide a way to define our own layout handles and call them explicitly through custom extensions. It’s easy to update unique page layouts by utilizing Magento’s built in ability to insert additional layout handles using an Observer. Let’s see how to create our own layout handles. The event
Scenario:
Wrong way to go:
$page = (int) Mage::app()->getRequest()->getParam('id'); if($page == '12') { $this->getLayout()->unsetBlock('header'); $this->getLayout()->unsetBlock('footer'); } Solution creating custom layout handle:
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); } } <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> controller_action_layout_load_before will attempt to run addCustomHandles function in the Oberserver every time the controller action is called.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>
Magento
How to Conditionally remove Magento header/footer?
<p>Are you looking for a solution to conditionally remove Magento header footer but don’t know where to start? Right in this post I will show you how to create custom layout handles and utilize them to conditionally remove header/footer blocks.</p>
· 5 min read
Related posts
Magento
Magento 1: Export manufacturers CSV by specific store view
This post will guide you on how you can export the manufacturer list (Magento 1.9) to CSV file. In this script, I am filtering the list by store view. Let’
Magento
Magento 1: Export catalog categories for a specific store view
In this post you will learn how you can export Magento 1.9 categories for a specific store view as CSV. For example, you have Arabic store view with ID 7, and y
Magento
Search Magento products by product labels
Project Overview: Task was to develop a Product Labels Magento extension. Where admin can create product labels by uploading an image, enter label title and att