Magento布局和分层导航

时间:2013-04-28 20:41:41

标签: magento magento-layout-xml

我正在尝试使用空模板创建一个自定义页面,其中包含以下XML。

在我的控制器中,我有

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

在我的布局中,我有

<?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>

此工作正常,并显示分层导航。

但是,我希望分层导航能够在brands.phtml模板中显示。 因此,我尝试执行以下操作:

<?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>

但是,当我在brands.phtml中调用getChildHtml(“catalog.leftnav”)时,这似乎不起作用。

如何将分层导航转移到我需要在brands.phtml中调用它的位置?

因此,当我在“Magento Debug”中查看“渲染块”部分时,似乎加载了块。但是,没有生成HTML。是否存在一条规则,即分层导航必须位于左侧/内容/右侧块中?

感谢

1 个答案:

答案 0 :(得分:0)

getChildHtml使用as属性查找子项,而不是其name属性。因此,请尝试将块定义更改为此并相应地更改getChildHtml调用:

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