在 Magento 中,最好不创建一个全新的模块,如何将现有模块的布局加载到我自己的模板中?
例如:我想加载“用户帐户仪表板”布局,但我想加载它以便我可以控制它与默认设置分开的外观。
结构如下:
我创建了一个带有 url “门户”的 CMS 页面。所以,导航是“ http://website.com/portal ”
CMS 页面使用“include()”来加载“/root/portal/portal.php”。这是我定义一个扩展 Mage_Page_Block_Html 的类的地方。
然后我添加了一个函数“renderDashboard()”从现有的仪表板布局加载到仪表板中。
我已将“/app/base/default/customer/account/dashboard.phtml”复制到“/root/portal/content/dashboard.phtml”以用作模板。在我的“dashboard.phtml”中,我希望“$this”对象的功能与之前的“dashboard.phtml”中的功能完全相同
“/root/portal/portal.php”
class Portal_Block extends Mage_Page_Block_Html
{
public function renderDashboard()
{
$layout = Mage::getSingleton('core/layout');
//Load existing "customer/account_dashboard" block into my own "dashboard.phtml"
$block = $layout->createBlock('customer/account_dashboard')->setTemplate('/root/portal/content/dashboard.phtml');
//Need to now add it
//$block->renderLayout();
}
}
如果这不可能,我将不得不在我的门户中重写整个帐户仪表板模块......所以,我真的希望它是可能的!