如何在文件phtml magento中添加文件phtml?

时间:2015-07-23 03:24:10

标签: php override magento-1.9

我想显示内容文件:frontend \ RWD \ default \ template \ customer / address / edit.phtm 在文件内:frontend \ RWD \ default \ template \ customer / account / dashboard.phtml。 我将此代码插入文件dashboard.phtml

<?php
$block = Mage::app()->getLayout()->createBlock('core/template')->setTemplate('customer/address/edit.phtml')->toHtml();
echo $block; ?>

2 个答案:

答案 0 :(得分:0)

该部分的正确块类型是customer / address_edit。所以请尝试以下方法:

<?php
$block = Mage::app()->getLayout()->createBlock('customer/address_edit')->setTemplate('customer/address/edit.phtml')->toHtml();
echo $block;
?>

答案 1 :(得分:0)

你应该使用渲染&#34;局部视图&#34;在这种情况下,而不是你的方式。

在Magento,方法有所不同。基本上,Magento使用与视图中的模板相关联的块,因此每个页面都包含一个块PHP类(它们都继承自Mage_Core_Block_Abstract),并且大多数(但也有例外)包含相关模板(phtml文件)。

要渲染部分,块可以在其中包含具有给定子名称的子块。从父块,您可以使用getChildHtml($ childName)呈现子块。要在子块中设置变量,可以使用魔术getter和setter,因为所有块PHP类最终都是从Varien_Object扩展的。

相关问题