通过$ this-> getChildHtml()调用magento模板 [英] Call magento template via $this->getChildHtml()
问题描述
我有一个联系表单模板(modal.phtml),我想将其添加到网站上的所有页面上,但是我需要能够精确定位它,因此我想使用$this->getChildHtml('contacts-modal')
,而不是通过布局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>
如果要使用$this->getChildHtml('contacts-modal')
插入模板,则必须在布局xml中声明模板,请查看类Mage_Core_Block_Abstract以查看getChildHtml的工作方式.
如果要将其添加到没有2columns-right作为主模板的其他页面,则必须像使用2columns-right一样添加xml引用,或者可以在父模板echo $this->getLayout()->createBlock('core/template')->setTemplate('contacts/modal.phtml')
I have a contact form template (modal.phtml), which I want to add to all pages on my site, but I need to be able to position it precisely, so I want to insert into the relevant page templates using $this->getChildHtml('contacts-modal')
, instead of inserting via layout xml. So in page/2columns-right.phtml, I want to use that call to insert the template stored in contacts/modal.phtml. The layout xml i have below is automatically inserting this template - how do i go about correcting this? Thanks for any pointers, and apologies if this is a very basic thing!
<reference name="content">
<block type="core/template" name="contacts-modal" as="contacts-modal" template="contacts/modal.phtml"/>
</reference>
If you want to insert the template with $this->getChildHtml('contacts-modal')
you have to declare it in the layout xml, look into the class Mage_Core_Block_Abstract to see how getChildHtml works.
If you want to add it to other pages that don't have 2columns-right as main template, you have to add the xml reference like you did with 2columns-right, or you can use inside the parent template echo $this->getLayout()->createBlock('core/template')->setTemplate('contacts/modal.phtml')
这篇关于通过$ this-> getChildHtml()调用magento模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!