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>
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>
Work with Scriptbaker
Let's talk about your project
Whether you're extending an existing platform, modernising legacy code, or planning something new, our engineers can help. Tell us what you're working on and we'll explore a practical technical solution together.
Related posts
Magento
Magento 1: Export Catalog Categories by Store View
Learn how to export Magento 1 catalog categories for a specific store view as a CSV file using a simple PHP script. This guide covers store-view IDs, localized category names, active and inactive categories, URL keys, SEO data, troubleshooting, CSV encoding, security considerations, and practical tips for managing multilingual Magento catalogs.
Magento
Magento 1: Export Manufacturers CSV by Store View
Learn how to export Magento 1 manufacturer attribute options to a CSV file for a specific Store View. This step-by-step guide includes a PHP script, multilingual store-view handling, troubleshooting tips, CSV best practices, and FAQs to help with Magento data migration, catalog management, and custom reporting.
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