【问题标题】:Call magento template via $this->getChildHtml()通过 $this->getChildHtml() 调用 magento 模板
【发布时间】:2013-08-09 11:43:45
【问题描述】:

我有一个联系表单模板 (modal.phtml),我想将它添加到我网站上的所有页面,但我需要能够准确定位它,所以我想使用 @ 插入到相关页面模板中987654321@,而不是通过布局 xml 插入。因此,在 page/2columns-right.phtml 中,我想使用该调用来插入存储在 contacts/modal.phtml 中的模板。我在下面的布局 xml 会自动插入这个模板 - 我该如何纠正这个?感谢您的任何指点,如果这是一个非常基本的事情,我们深表歉意!

       <reference name="content">
            <block type="core/template" name="contacts-modal" as="contacts-modal" template="contacts/modal.phtml"/>
        </reference>

【问题讨论】:

  • 如果将它包含在页脚中并通过 javascript 定位它会不会更好?...只是说

标签: magento


【解决方案1】:

如果您想插入带有$this-&gt;getChildHtml('contacts-modal') 的模板,您必须在布局xml 中声明它,查看Mage_Core_Block_Abstract 类以了解getChildHtml 是如何工作的。 如果要将其添加到没有 2columns-right 作为主模板的其他页面,则必须像使用 2columns-right 一样添加 xml 引用,或者您可以在父模板中使用 echo $this-&gt;getLayout()-&gt;createBlock('core/template')-&gt;setTemplate('contacts/modal.phtml')

【讨论】:

  • 感谢艾米的回复。我希望在那里使用你的最后一个建议,但是从 2columns-right.phtml 调用它,例如,抛出:可恢复错误:Mage_Core_Block_Template 类的对象无法转换为字符串
  • 我所需要的只是将 ->toHtml() 添加到该调用的末尾。现在完美运行,谢谢
猜你喜欢
  • 1970-01-01
  • 2012-06-09
  • 1970-01-01
  • 2012-07-18
  • 2013-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多