简体   繁体   English

Magento布局和分层导航

[英]Magento Layout and Layered Navigation

I am trying to create a custom page for which I have the following XML using an empty template. 我试图创建一个自定义页面,使用空模板为其提供以下XML。

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. 但是,我希望分层导航显示在brand.phtml模板中。 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. 但是,当我在brand.phtml中调用getChildHtml(“ catalog.leftnav”)时,这似乎不起作用。

How do I shift the layered navigation to where I need to call it in brands.phtml? 如何将分层导航移动到需要在brand.phtml中进行调用的位置?

So, it seems like the block is loaded when I view the "rendered blocks" section in "Magento Debug".. However, no HTML is generated. 因此,当我在“ Magento调试”中查看“渲染的块”部分时,似乎加载了该块。但是,没有生成HTML。 Is there a rule that says that the layered navigation has to be in the left/content/right blocks or something? 是否有规则说分层导航必须在left / content / right块之内?

THanks 谢谢

getChildHtml looks for children using their as attribute, not their name attribute. getChildHtml使用其as属性(而不是其name属性)查找子级。 So try changing your block definition to this and change the getChildHtml call accordingly: 因此,尝试将您的块定义更改为此,并相应地更改getChildHtml调用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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