Showing results for 
Search instead for 
Did you mean: 

Showing layered navigation filter in two block locations - will only render if in one XML block

Showing layered navigation filter in two block locations - will only render if in one XML block

I have the XML below in my layout. Notice that both category.products and product_list have the block type amshopby/catalog_layer_view_top. The reason for this is that under certain conditions category.products will render this block and in all other circumstances product_list will render the block. If I remove one of the references to this block so that it is only in my XML once, the block renders its content. When it is in the XML twice, a method within the template (canShowBlock) becomes false and the content does render.

    <remove name="catalog.leftnav" />
    <remove name="enterprisecatalog.leftnav"/>
    <reference name="left">
       <block type="amshopby/catalog_layer_view" name="amshopby.navleft" before="-" template="catalog/layer/view.phtml"/>
    <reference name="category.products">
        <block type="amshopby/catalog_layer_view_top" name="amshopby.navtop.category.view" template="amasty/amshopby/view_top.phtml">
            <block type="core/template" name="" as="filterSearch.category.view" template="catalogsearch/form.filter.phtml"/>
    <reference name="product_list">
        <block type="amshopby/catalog_layer_view_top" name="amshopby.navtop" template="amasty/amshopby/view_top.phtml">
            <block type="core/template" name="" as="filterSearch" template="catalogsearch/form.filter.phtml"/>
    <reference name="content">
        <block type="amshopby/top" name="" before="category.products" template="amasty/amshopby/top.phtml"/>


The block is inserted as it should be. However, the template content is wrapped in the condition below and canShowBlock() is returning false when the block is in the XML twice.

<?php /** @var $this Amasty_Shopby_Block_Catalog_Layer_View_Top */ ?>
<?php if($this->canShowBlock()): 
    //Contents of template

The canShowBlock() method (shown below) is within class Amasty_Shopby_Block_Catalog_Layer_View which, eventually, extends Enterprise_Search_Block_Catalog_Layer_View.

canShowOptions() is what "breaks" (returns false) when the block is in the XML twice. This method is called from Mage_Catalog_Block_Layer_View

public function canShowBlock()
    if ($this->canShowOptions()){
        return true;

    $cnt = 0;
    $pos = Mage::getStoreConfig('amshopby/block/state_pos'); 
    if (!$this->_notInBlock($pos)){
        $cnt = count($this->getLayer()->getState()->getFilters());
    return $cnt;