Magento Custom Category Layout Not Working – Troubleshooting Guide

layoutmagento-1.7

I created a module as per the steps described in the accepted answer from the following question:

Adding custom layouts for CMS and Category use with custom module trouble

However, the block updates that should be applied to the left section of the page as defined in isn_layouts.xml do not get applied.

Even if I change the template filename to a non-existent file it still does not produce an error which suggests to me that Magento is not seeing the layout updates in the app/design/frontend/base/default/layout/isn_layouts.xml file.

The code for the module is as follows:

app/etc/modules/ISN_Layouts.xml:

<?xml version="1.0"?>
<config>
  <modules>
    <ISN_Layouts>
      <active>true</active>
      <codePool>local</codePool>
      <depends>
        <Mage_Page />
      </depends>
    </ISN_Layouts>
  </modules>
</config>

app/code/local/ISN/Layouts/etc/config.xml:

<?xml version="1.0"?>
<config>
  <modules>
    <ISN_Layouts>
      <version>0.0.1</version>
    </ISN_Layouts>
  </modules>
  <global>
    <page>
      <layouts>
        <noanchor module="page" translate="label">
          <label>Anchor Override</label>
          <template>page/3columns.phtml</template>
          <layout_handle>noanchor</layout_handle>
        </noanchor>
      </layouts>
    </page>
  </global>
  <frontend>
    <layout>
      <updates>
        <isn_layouts>
          <file>isn_layouts.xml</file>
        </isn_layouts>
      </updates>
    </layout>
  </frontend>
</config>

app/design/frontend/base/default/layout/isn_layouts.xml:

<?xml version="1.0"?>
<layout>
  <noanchor translate="label">
    <label>Anchor Override</label>
    <reference name="root">
      <action method="setTemplate"><template>page/3columns.phtml</template></action>
      <action method="setIsHandle"><applied>1</applied></action>
    </reference>
    <reference name="left">
      <action method="unsetChild"><name>catalog.leftnav</name></action>
      <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
    </reference>
  </noanchor>
</layout>

What am I doing wrong?

Best Answer

If you just want to avoid layered navigation for a category, then you can go with one of following options:

  1. Make your category a default category. You can do this by setting isAnchor to No from admin side by selecting the categories that you need. Now your category will not use layered navigation and thus you will get required behaviour. isAnchor-to-No

  2. Put this code inside Custom Layout Update section inside your category page (by editing via admin)

        <reference name="left">
            <action method="unsetChild"><name>catalog.leftnav</name></action>
            <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
        </reference>
    

CustomDesignTab-of-category

  1. Or use this below code if you want to go with layout update method only.

File : app\design\frontend\{package}\{theme}\layout\local.xml

    <?xml version="1.0"?>
    <layout>
        <CATEGORY_{ID}>
            <reference name="left">
                <action method="unsetChild"><name>catalog.leftnav</name></action>
                <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
            </reference>
        </CATEGORY_{ID}>
    </layout>

where {ID} should replace with category-id of your specific category. For an example, if category id is 15, then layout update handle will be CATEGORY_15

Hope that makes sense.

EDIT - 1

This is the final solution which came to my mind.You need to include page layout handle as one of the layout update handle for category page.

For this, observe to the event controller_action_layout_load_before and put this inside your observer

<?php
class ISN_Layouts_Model_Observer
{
    public function beforeLoadLayout(Varien_Event_Observer $observer)
    {
        $layout = $observer->getEvent()->getLayout();
        if (Mage::registry('current_category')) {
            $category = Mage::registry('current_category');
            $settings = Mage::getSingleton('catalog/design')
                ->getDesignSettings($category);
            $pl = $settings->getPageLayout();
            if ($pl) {
                $layout->helper('page/layout')->applyHandle($pl);
            }
        }
        return $this;
    }
}

You are done. Now clear your cache and you will see the changes that you have specified within your page layout handle, ie noanchor

EDIT - 2

Here is your full extension. Please checkout and feel free to use it.

EDIT - 3

For category pages, you can use the following condition check

if ($observer->getEvent()->getAction()->getFullActionName() == 'catalog_category_view') {
     //go on
}

See the changes in Observer.php in github.


Note : Out of 3 options, use only one option at a time. Dont forget to clear your cache after changes made.