【问题标题】:Grabbing Magento phtmls from outside of Magento while keeping data intact从 Magento 外部获取 Magento phtml,同时保持数据完整
【发布时间】:2011-10-19 14:34:37
【问题描述】:

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

在 Magento 之外,处理日期仍然完好无损。 就像我的意思是仍然为用户“我的购物车 (5)”显示正确的项目数量,或者在标题中显示“欢迎,volkan yavuz”并且仍然显示用户的姓名。

我为什么要这个?

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

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

【问题讨论】:

    标签: magento frameworks enterprise


    【解决方案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();
    

    您可以选择为所有块创建一个包含块,将您的块设置为该块的子块,在其中进行适当的模板和getChildHtml() 调用,然后您只需在该块上调用toHtml()

    HTH!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-24
      • 1970-01-01
      • 2015-05-27
      相关资源
      最近更新 更多