简体   繁体   English

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

[英]how to add file phtml in file phtml magento?

I want to show the contents file: frontend \\ RWD \\ default \\ template \\ customer / address / edit.phtm inside the file: frontend \\ RWD \\ default \\ template \\ customer / account / dashboard.phtml. 我想显示内容文件:文件内的frontend \\ RWD \\ default \\ template \\客户/地址/ edit.phtm文件内:frontend \\ RWD \\ default \\ template \\客户/帐户/dashboard.phtml。 i insert this code into the file dashboard.phtml 我将此代码插入文件dashboard.phtml

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

The correct block type for that section is customer/address_edit. 该部分的正确块类型是customer / address_edit。 So please try the following: 因此,请尝试以下操作:

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

You should use the render "partial views" in this case instead the way you did. 在这种情况下,应使用渲染的“局部视图”,而不是原来的方式。

In Magento, the approach is somewhat different. 在Magento中,方法有些不同。 Basically, Magento uses Blocks which are associated with templates in the view, so each page consists of both a block PHP class (they all inherit from Mage_Core_Block_Abstract) and mostly (but there are exceptions) an associated template (phtml file). 基本上,Magento使用与视图中的模板相关联的Blocks,因此每个页面都包含一个PHP模块类(它们都从Mage_Core_Block_Abstract继承)以及大部分(但有例外)相关模板(phtml文件)组成。

To render partials, blocks can have child blocks within them with given child names. 要渲染局部,块中可以包含带有给定子名称的子块。 From the parent block, you can render the child blocks using getChildHtml($childName). 在父块中,可以使用getChildHtml($ childName)渲染子块。 To set variables at the child block, you can use the magic getter and setters, because all block PHP classes ultimately extend from Varien_Object. 要在子块上设置变量,可以使用魔术getter和setter,因为所有块PHP类最终都从Varien_Object扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM