【问题标题】:Display custom block at Magento Home page在 Magento 主页显示自定义块
【发布时间】:2013-10-23 17:09:09
【问题描述】:

我看到了这个答案Static block on home page in Magento,但无法让它发挥作用。

我只是想在我的主页中添加一个自定义块。这些是我做过的事情:

1- 将此添加到我的布局文件中。

<cms_index_index>
    <reference name="content">
       <block type="aitshopassist/assistant" name="aitshopassist_assistant" template="aitshopassist/assistant.phtml">
           <action method="setBlockId"><block_id>shop_assistant_block</block_id>
           </action>
       </block>
     </reference>
</cms_index_index>

2- 将此添加到 2columns-right.phtml 文件中:

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

此外,该块在 catalog_category_view 中正确显示。

我错过了什么?

<catalog_category_view>
    <reference name="content">
        <block type="aitshopassist/assistant" name="aitshopassist_assistant" template="aitshopassist/assistant.phtml" before="category.products" />
    </reference>
</catalog_category_view>

我在 cms_index_index 中尝试过,但没有用..

【问题讨论】:

  • getChildHtml 方法将查看name 值,即aitshopassist_assistant,而不是shop_assistant_block。这在catalog_category_view 中如何正确显示?你能把你用来弹出它的布局更新粘贴到那里吗?
  • 我编辑问题,有布局的目录代码。谢谢

标签: php magento


【解决方案1】:
 <block type="cms/block" name="aitshopassist_assistant" before="-">
        <action method="setBlockId"><block_id>shop_assistant_block</block_id></action>
  </block>

在xml文件中设置调用块

【讨论】:

    【解决方案2】:

    只需在您的主 phtml 文件中回显以下代码:

    $this->getLayout() ->getBlockSingleton('aitshopassist/assistant')->setTemplate('aitshopassist/assistant.phtml')->toHtml();
    

    【讨论】:

      猜你喜欢
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多