使用时无法呈现的引用中的嵌套块 - > getChildHtml()

时间:2013-11-03 14:24:52

标签: magento block magento-layout-xml

这是我的布局xml:

<catalog_category_default translate="label">
        <label>Catalog Category (Non-Anchor)</label>
        <reference name="content">
            <block type="core/template" name="page.brand" template="page/brand.phtml" />
            <block type="catalog/product_list" template="page/accessories.phtml">
                 <block type="catalog/navigation" name="catalog.leftnav" as="filter_menu" template="catalog/navigation/left.phtml"/> 
            </block>
        </reference>
</catalog_category_default>

从page.accessories.phtml中,在一个div块里面我打电话:

<?php echo $this->getChildHtml('filter_menu') ?>

但没有任何结果。这是为什么?

这是来自分层phtml文件的代码:

<div class="oh_shit"></div>
<?php if($this->canShowBlock()): ?>
<div class="block block-layered-nav">
    <div class="block-title">
        <strong><span><?php echo $this->__('Shop By') ?></span></strong>
    </div>
    <div class="block-content">
        <?php echo $this->getStateHtml() ?>
        <?php if ($this->getLayer()->getState()->getFilters()): ?>
            <div class="actions"><a href="<?php echo $this->getClearUrl() ?>"><?php echo $this->__('Clear All') ?></a></div>
        <?php endif; ?>
        <?php if($this->canShowOptions()): ?>
            <p class="block-subtitle"><?php echo $this->__('Shopping Options') ?></p>
            <dl id="narrow-by-list">
                <?php $_filters = $this->getFilters() ?>
                <?php foreach ($_filters as $_filter): ?>
                <?php if($_filter->getItemsCount()): ?>
                    <dt><?php echo $this->__($_filter->getName()) ?></dt>
                    <dd><?php echo $_filter->getHtml() ?></dd>
                <?php endif; ?>
                <?php endforeach; ?>
            </dl>
            <script type="text/javascript">decorateDataList('narrow-by-list')</script>
        <?php endif; ?>
    </div>
</div>
<?php endif; ?>

2 个答案:

答案 0 :(得分:1)

尝试将布局xml中的块添加到:

<catalog_category_layered translate="label">
    <label>Catalog Category</label>
    <reference name="content">
        <block type="core/template" name="page.brand" template="page/brand.phtml" />
        <block type="catalog/product_list" template="page/accessories.phtml">
             <block type="catalog/navigation" name="catalog.leftnav" as="filter_menu" template="catalog/navigation/left.phtml"/> 
        </block>
    </reference>
</catalog_category_layered>

答案 1 :(得分:1)

确定。我知道了。我不小心删除了类型=“product_list”的块上的name属性。当我重新添加name =“product_list”时,它有效。