从Magento外部抓取Magento phtmls,同时保持数据完好无损

时间:2011-10-19 14:34:37

标签: magento frameworks enterprise

如何获取以下文件的内容     frontend/enterprise/default/template/page/html/header.phtml或     frontend/base/default/template/page/template/links.phtml或     frontend/enterprise/default/template/checkout/cart/cartheader.phtml

在Magento之外,仍然保持处理日期不变。 就像我的意思是仍然显示用户'我的购物车(5)'的正确数量的项目,或在标题中显示'欢迎,volkan yavuz'并仍然显示用户的名字。

为什么我要这个?

我有一个独立于Magento的zend应用程序,我们正在尝试将页眉和页脚组合在一起,因此我们将它们放在一个地方。我们需要从这个zend应用程序中调用Magento头文件。

到目前为止,我在Magento中创建了一个调用这些文件(phtml)的自定义API,但我似乎无法获取这些处理过的数据(例如当前会话/用户的购物车编号或欢迎名字姓氏消息。

1 个答案:

答案 0 :(得分:1)

为了使用正确的数据和数据进行渲染。状态,它们必须具有正确的渲染环境。

<?php
include 'app/Mage.php';
Mage::app('store_code');

//Load the session so we get quotes.
Mage::getSingleton('core/session', array('name' => 'frontend'))->start();
/*
   see Mage_Core_Controller_Varien_Action::preDispatch()
   and Mage_Core_Controller_Front_Action::preDispatch()
*/

//For each block you wish to render, you could do the following:
$output = Mage::app()->getLayout()
                     ->createBlock('block/type')
                     ->setTemplate('template/path.phtml')
                     ->toHtml();

您可以选择为所有块创建一个包含块,将块设置为此块的子块,制作相应的模板&amp; getChildHtml()在其中调用,然后您只需在该块上调用toHtml()

HTH!