【问题标题】:Get a block type of a page Magento获取页面 Magento 的块类型
【发布时间】:2017-05-01 17:33:44
【问题描述】:

我想知道如何找到某些页面示例的块类型:主页。

我的主页有问题,我想在 xml 中显示一些块,我在 <cms_index_index> (local.xml) 中声明了我的块,但如果我把它放在 <reference name="head"> 中,它会出现,如果 @987654323 @ 或 <reference name="content"> 它不起作用。在我看来,块的类型不好。

xml:

<cms_index_index>
        <reference name="root">
            <block type="core/template" name="seconnecter_test" template="customer/form/test-seconnecter.phtml"/>
        </reference>
</cms_index_index>

在主页 1column-full.phtml 我这样称呼它:

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

【问题讨论】:

  • 解决方案:$this->getBlockHtml('name_block');

标签: magento magento-1.7 magento-1.9 magento-1.8 magento-1.4


【解决方案1】:

当你给&lt;reference name="content"&gt;他们的块类型是core/text_list。此块类型自动输出其内容,无需使用getchildhtml()

在你的 local.xml

<?xml version="1.0"?>
 <layout version="0.1.0">
   <cms_index_index>
     <reference name="content">
       <block type="core/template" name="seconnecter_test" before="_" template="customer/form/test-seconnecter.phtml"/>
     </reference>
    </cms_index_index>
 </layout>

将模板文件放在正确的位置,块将呈现在内容的顶部。

或者试试这个从管理面板转到cms-&gt;pages-&gt;homepage。在设计部分的布局更新xml中添加以下内容

  <reference name="content">
       <block type="core/template" name="seconnecter_test" before="_" template="customer/form/test-seconnecter.phtml"/>
   </reference>

刷新缓存。

【讨论】:

  • 我对此进行了测试,但它不起作用!。我使用了 Suman Singh 的解决方案,但它向我显示了底部的块,而我想在一些块之后将它显示在中间,这就是为什么我想在 phtml 中使用引用 name="root" 和 get child。
  • 你可以把 getchildhtml() 调用放在你想要的地方。
  • 是的,但是您的解决方案没有显示任何内容,我使用了 output="toHtml" 和 getChildHtml 它可以工作,但它显示了页脚下方的块,我不想要这个,我想显示它代替 getChildHtml。
  • 我没有这个页面,我不想通过管理员
【解决方案2】:

你可以使用

<reference name="root">
    <block type="core/template" name="seconnecter_test" output="toHtml" template="customer/form/test-seconnecter.phtml"/>
</reference>

【讨论】:

  • 使用 output="toHtml" 将你的块作为输出块,只有输出块会被自动渲染。
  • 我测试过它可以工作,但它显示了页面底部的块,而我想在一些块之后将它显示在中间这就是为什么我想使用参考 name="root"和 phtml 中的 get child。
  • 您可以在块定义中使用 before/after 属性。
  • 我使用了 before="content" 或 before="header" 它不起作用
  • 我找到了一个解决方案,在我使用的主页中显示我的块: $this->getBlockHtml('name_block');我不知道为什么 getChildHtml('') 在内容和标题中不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-10
  • 2016-06-27
相关资源
最近更新 更多