让我知道如何将“checkout / cart_sidebar”块作为HTML变为变量? 我需要从我自己的magento控制器中获取它
我看到“checkout / cart_sidebar”取决于“Mage_Checkout_Block_Cart_Sidebar”类
所以可以通过一些Mage :: Static Instance Methods
来获取此模板我尝试了几种方法(
感谢
答案 0 :(得分:2)
在您的控制器中,您可以尝试这样的事情:
$block = $this->getLayout()->createBlock('checkout/cart_sidebar');
$block->setTemplate('checkout/cart/sidebar.phtml');
根据您的配置(配置 - >结帐 - >购物车边栏),您可以使用
呈现模板 $block->toHtml();
如果您使用自定义模板,则可以忽略配置值,以便随时呈现。
答案 1 :(得分:1)
布局xml配置中的操作只是一个块方法调用。
下面两个是相同的
<block type = "checkout/cart_sidebar"
name = "cart_sidebar"
as = "cartExplorer"
template = "checkout/cart/sidebar.phtml"
before = "-">
<action method="addItemRender">
<type>configurable</type>
<block>checkout/cart_item_renderer_configurable</block>
<template>checkout/cart/sidebar/default.phtml</template>
</action>
<!-- Programatically create the block -->
<?php
$this->getLayout()
->createBlock('checkout/cart_sidebar', 'cart_sidebar')
->setTemplate('checkout/cart/sidebar.phtml');
->addItemRender(
'configurable',
'checkout/cart_item_renderer_configurable',
'checkout/cart/sidebar/default.phtml'
)
?>
<!-- This is if it was already created in a layout.xml file -->
<?php
$this->getLayout()
->getBlock('cart_sidebar')
->addItemRender(
'configurable',
'checkout/cart_item_renderer_configurable',
'checkout/cart/sidebar/default.phtml'
)
?>
希望这有帮助!