如何在文件 phtml magento 中添加文件 phtml?
how to add file phtml in file phtml magento?
我要显示的内容文件: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; ?>
该部分的正确块类型是 customer/address_edit。所以请尝试以下操作:
<?php
$block = Mage::app()->getLayout()->createBlock('customer/address_edit')->setTemplate('customer/address/edit.phtml')->toHtml();
echo $block;
?>
在这种情况下,您应该使用渲染器 "partial views",而不是像您那样使用。
在 Magento 中,方法有些不同。基本上,Magento 使用与视图中的模板关联的块,因此每个页面都包含块 PHP class(它们都继承自 Mage_Core_Block_Abstract)和大部分(但也有例外) ) 关联模板(phtml 文件)。
为了呈现部分,块可以在其中包含具有给定子名称的子块。从父块,您可以使用 getChildHtml($childName) 呈现子块。要在子块中设置变量,您可以使用魔术 getter 和设置器,因为所有块 PHP classes 最终都从 Varien_Object.
扩展
我要显示的内容文件: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; ?>
该部分的正确块类型是 customer/address_edit。所以请尝试以下操作:
<?php
$block = Mage::app()->getLayout()->createBlock('customer/address_edit')->setTemplate('customer/address/edit.phtml')->toHtml();
echo $block;
?>
在这种情况下,您应该使用渲染器 "partial views",而不是像您那样使用。
在 Magento 中,方法有些不同。基本上,Magento 使用与视图中的模板关联的块,因此每个页面都包含块 PHP class(它们都继承自 Mage_Core_Block_Abstract)和大部分(但也有例外) ) 关联模板(phtml 文件)。
为了呈现部分,块可以在其中包含具有给定子名称的子块。从父块,您可以使用 getChildHtml($childName) 呈现子块。要在子块中设置变量,您可以使用魔术 getter 和设置器,因为所有块 PHP classes 最终都从 Varien_Object.
扩展