【问题标题】:getChildHtml() method not working in product list page (category view.phtml/ product list.phtml) in magentogetChildHtml() 方法在 magento 的产品列表页面(类别 view.phtml/product list.phtml)中不起作用
【发布时间】:2013-05-08 09:27:47
【问题描述】:

我在 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') ?>

请帮帮我。

【问题讨论】:

  • 你有没有在你的系统中创建了newreference,基本上在另一个reference中调用一个reference是错误的
  • 是的,我已经在 page.xml 文件中创建了它。

标签: magento magento-1.7 magento-1.6


【解决方案1】:

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

<?php echo $this->getLayout()->getBlock('yourblockname')->toHtml(); ?> 

【讨论】:

    【解决方案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') ?>
    

    【讨论】:

    • Nupp @zitix,它对我不起作用...... :(。实际上我想从 list.phtml 调用参考。
    • 但是为什么你把 放在 里面呢?贴更多代码,很难弄清楚你到底想做什么。
    • 问题解决了,是的,这也是错误的,我从那里删除了对外部的引用。现在它工作正常。 :),顺便说一句,谢谢你的时间@zitix ..!! :)
    • 没问题。 :) 您可以编辑您的帖子以显示正确的最终代码,这可能对其他人有用。
    【解决方案3】:

    将新引用块放在内容块之外。

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

    【讨论】:

    • 是的,它工作得很好,但问题是,我想在工具栏/寻呼机下方显示我的参考 newreference,所以我需要在内容块下调用它。
    • 好的,所以您不需要为您的要求创建新引用,只需在工具栏块下调用您的块并删除您的新引用标记,然后在工具栏块&lt;?php echo $this-&gt;getChildHtml('newreferenceblock') ?&gt; 之后的 list.phtml 文件中输入此代码,然后您完成了
    • 我已经这样做了,但它不起作用。我必须这样做,因为我需要在左侧边栏中调用一些其他块,所以我正在尝试创建自己的左侧边栏引用,并且我想显示寻呼机/工具栏来代替面包屑。
    • 如果您愿意在左侧边栏中显示,那么由于工具栏在内容区域中,工具栏部分下的内容如何显示?
    • 是的,工具栏在内容区。我想显示工具栏代替面包屑。我想在工具栏下显示左侧边栏,除了左侧边栏,在内容区域,我想显示产品列表。那是我的目标。
    【解决方案4】:
    <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 是我的自定义块,我将其用作侧边栏。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多