1

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?

  • Is there a specific reason you are creating a new layout handle? Are you just trying to remove the left nav from the layered nav category page? – Bobadevv Sep 17 '15 at 17:09
  • We have some categories that are anchors, and we want to make them behave like normal non-anchor categories by removing the layered navigation and replacing that with the standard category links. – Chris Sep 17 '15 at 20:23
3

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.

  • Nice! I was going to update my answer with method 2, all 3 options here are sound advice – Bobadevv Sep 18 '15 at 5:26
  • 1
    @Chris follow this tutorial for setup an observer in your module magento.stackexchange.com/questions/41277/… . our event is controller_action_layout_load_before – Rajeev K Tomy Sep 18 '15 at 12:47
  • 1
    @Chris see edit-2 and let me know your doubts – Rajeev K Tomy Sep 18 '15 at 13:15
  • 1
    @Chris you can check Mage::registry('current_product') in that case. if it is null, then it will be a cetegory page. another solution is, $observer->getControllerAction()->getRequest()->getFullActionName() === 'catalog_category_view' – Rajeev K Tomy Sep 29 '15 at 15:33
  • 1
    @Chris Please see edit -3 – Rajeev K Tomy Sep 30 '15 at 1:37
0

Rather than the approach you have taken you can achieve this through the following steps.

Add a local.xml file to your theme in the following directory.

app/design/frontend/yourpackage/yourtheme/layout/local.xml

Add the following xml to remove the layered nav and add the standard category links block.

<?xml version="1.0"?>
<layout>    
<catalog_category_layered>
        <reference name="left">
            <block type="catalog/navigation" name="catalog.leftnav.categories" after="currency" template="catalog/navigation/left.phtml"/>
        </reference>
        <reference name="catalog.leftnav">
            <action method="unsetChild"><child>category_filter</child></action>
        </reference>
    </catalog_category_layered>
</layout>

After you have added the local.xml file with the XML update clear all caches and your all set

  • Thanks for this. How would we do this for specific categories only? This is why we wanted to create a new page layout so we could select it for specific categories only. Some categories should remain as normal. – Chris Sep 17 '15 at 21:49
  • Id go with approach 2 Rajeev has suggested, add xml update within admin area. Id find this the easiest to manage but its what ever works best for you – Bobadevv Sep 18 '15 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.