简体   繁体   中英

Magento Layout and Layered Navigation

I am trying to create a custom page for which I have the following XML using an empty template.

In my Controller, I have

public function indexAction()
{
        $this->loadLayout();
        $this->getLayout()->getBlock('root')->setTemplate('page/empty.phtml');
        $this->renderLayout();
}

And in my layout, I have

<?xml version="1.0"?>
<layout version="0.1.0">
    <brands_index_index>
        <reference name="content">
            <block type="catalog/layer_view" name="catalog.leftnav" before="brands" template="catalog/layer/view.phtml"/>
            <block type="core/template" name="brands" template="brands/brands.phtml" />
        </reference>
    </brands_index_index>
</layout>

This works fine and the layered navigation is displayed.

However, I want the layered navigation to be displayed within the brands.phtml template. Thus, I tried to do the following:

<?xml version="1.0"?>
<layout version="0.1.0">
    <brands_index_index>
        <reference name="content">
            <block type="core/template" name="brands" template="brands/brands.phtml" >
                <block type="catalog/layer_view" name="catalog.leftnav" as="catalog.leftnav" template="catalog/layer/view.phtml"/>
            </block>
        </reference>
    </brands_index_index>
</layout>

However, this does not seem to work when I call getChildHtml("catalog.leftnav") within brands.phtml.

How do I shift the layered navigation to where I need to call it in brands.phtml?

So, it seems like the block is loaded when I view the "rendered blocks" section in "Magento Debug".. However, no HTML is generated. Is there a rule that says that the layered navigation has to be in the left/content/right blocks or something?

THanks

getChildHtml looks for children using their as attribute, not their name attribute. So try changing your block definition to this and change the getChildHtml call accordingly:

<block type="catalog/layer_view" name="catalog.leftnav" as="mynav" template="catalog/layer/view.phtml" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM