【问题标题】:Magento - echo block within another blockMagento - 在另一个块内回显块
【发布时间】:2014-07-20 13:23:06
【问题描述】:

我有一个名为 Home 的 CMS 页面,在 Design->Layout Update Xml 中有以下代码

<reference name="content">
    <block type="core/template" template="homepage/home.phtml">
        <reference name="featured">
            <block type="catalog/product_list" name="featured" template="catalog/product/list.phtml">
                <action method="setCategoryId"><category_id>2</category_id></action>
                <action method="setColumnCount"><count>5</count></action>
            </block>
        </reference>
    </block>
</reference>

这个在 homepage/home.phtml 中

<div class="container home">
        <div class="promo">
           // Promo Here
        </div>

        <?php echo $this->getChildHtml('featured'); ?>
</div>

我的主要目标是尝试将特色块插入到 homepage/home.phtml 模板中,但是上面 CMS 页面中的当前布局 xml 没有显示。

非常感谢所有帮助。

【问题讨论】:

    标签: php magento magento-layout-xml


    【解决方案1】:

    xml 文件有问题,我已经修改...代码

    <reference name="content">
        <block type="core/template" template="homepage/home.phtml" >
                <block type="catalog/product_list" name="featured" template="catalog/product/list.phtml">
                    <action method="setCategoryId"><category_id>2</category_id></action>
                    <action method="setColumnCount"><count>5</count></action>
                </block>
        </block>
    </reference>
    

    其他都一样..

    【讨论】:

    • 我刚试过这个,product_list 仍然没有使用&lt;?php echo $this-&gt;getChildHtml('featured'); ?&gt; 在主页/page.phtml 中回显...我是否需要在其他地方进行更改才能使内部回显起作用?
    【解决方案2】:

    getChildHtml('精选'); ?> 'featured' 是块的名称而不是引用。如果你想在模板中调用块,你将使用以下块语法 {{block type="catalog/product_list" name="featured" as="featured" template="catalog/product/list.phtml"}}

    【讨论】:

      【解决方案3】:

      这样修改代码,我相信块的名称“home_content”应该在那里。

      <reference name="content">
          <block type="core/template" name="home_content" template="homepage/home.phtml" >
              <block type="catalog/product_list" name="featured" template="catalog/product/list.phtml">
                  <action method="setCategoryId"><category_id>2</category_id></action>
                  <action method="setColumnCount"><count>5</count></action>
              </block>
          </block>
      </reference>
      

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 2014-10-12
        • 2022-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-02
        • 1970-01-01
        相关资源
        最近更新 更多