1

我在 getToolbarHtml() 之后在 list.phtml 文件中调用我新创建的引用。但它没有显示任何东西。我的 catalog.xml 文件看起来像:

<reference name="content">
            <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
                <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
                    <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                        <block type="page/html_pager" name="product_list_toolbar_pager"/>

                        <!-- The following code shows how to set your own pager increments -->
                        <!--
                            <action method="setDefaultListPerPage"><limit>4</limit></action>
                            <action method="setDefaultGridPerPage"><limit>9</limit></action>
                            <action method="addPagerLimit"><mode>list</mode><limit>2</limit></action>
                            <action method="addPagerLimit"><mode>list</mode><limit>4</limit></action>
                            <action method="addPagerLimit"><mode>list</mode><limit>6</limit></action>
                            <action method="addPagerLimit"><mode>list</mode><limit>8</limit></action>
                            <action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
                        -->
                    </block>
                    <reference name="newreference">
                        <block type="core/template" name="newreferenceblock" template="newreference.phtml" />
                    </reference>

                    <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
                    <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>

                </block>
                    </block>

我在参考中调用参考,问题是我想创建自己的侧边栏。那么它有什么问题呢?在 list.phtml 中,我通过以下方式调用我的参考:

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

请帮我。

4

4 回答 4

5

请使用以下方法(请记住在内容下的 catelog.xml 中更新您的 xml):

<?php echo $this->getLayout()->getBlock('yourblockname')->toHtml(); ?> 
于 2013-06-17T10:19:43.937 回答
2

代替:

<reference name="newreference">
    <block type="core/template" name="newreferenceblock" template="newreference.phtml" />
</reference>

和:

<block type="core/template" name="newreferenceblock" template="newreference.phtml" />

然后使用'newreferenceblock'作为块的名称在模板中调用你的块:

<?php echo $this->getChildHtml('newreferenceblock') ?>
于 2013-05-08T09:47:27.080 回答
0

Put your newreference block out side of your content block.

<?php echo $this->getChildHtml('newreference') ?> call this block in one of your layout file something like below its for 2columns-right layout

<div class="main-container col2-right-layout">
        <div class="main">
            <?php echo $this->getChildHtml('breadcrumbs') ?>
            <div class="col-main">
                <?php echo $this->getChildHtml('global_messages') ?>
                <?php echo $this->getChildHtml('content') ?>
            </div>
            <div class="col-right sidebar"><?php echo $this->getChildHtml('right') ?></div>
        </div>
        <div><?php echo $this->getChildHtml('newreference') ?></div>
    </div>
于 2013-05-08T10:00:33.093 回答
0
<reference name="content">
            <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
                <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">

                     <block type="core/text_list" name="left_custompage" as="left_custompage">
                        <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
                     </block>
                    <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                        <block type="page/html_pager" name="product_list_toolbar_pager"/>
                        <!-- The following code shows how to set your own pager increments -->
                        <!--
                            <action method="setDefaultListPerPage"><limit>10</limit></action>
                            <action method="setDefaultGridPerPage"><limit>8</limit></action>
                            <action method="addPagerLimit"><mode>list</mode><limit>10</limit></action>
                            <action method="addPagerLimit"><mode>list</mode><limit>20</limit></action>
                            <action method="addPagerLimit"><mode>list</mode><limit>30</limit></action>
                            <action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
                            <action method="addPagerLimit"><mode>grid</mode><limit>8</limit></action>
                            <action method="addPagerLimit"><mode>grid</mode><limit>16</limit></action>
                            <action method="addPagerLimit"><mode>grid</mode><limit>24</limit></action>
                            <action method="addPagerLimit" translate="label"><mode>grid</mode><limit>all</limit><label>All</label></action>
                        -->
                    </block>
                    <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
                    <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
                </block>
            </block>

custompage 是我的自定义块,我将其用作侧边栏。

于 2013-05-09T04:40:24.910 回答