【问题标题】:How to get checkout/cart_sidebar block in Magento from everywhere如何从任何地方获取 Magento 中的 checkout/cart_sidebar 块
【发布时间】:2014-07-08 13:20:09
【问题描述】:

让我知道如何将“checkout/cart_sidebar”块作为 HTML 放入变量中? 我需要从我自己的 magento 控制器中获取它

我看到“checkout/cart_sidebar”依赖于“Mage_Checkout_Block_Cart_Sidebar”类

所以可以通过一些 Mage:: 静态实例方法获取此模板

我尝试了一些我无法做到的方法(

谢谢

【问题讨论】:

  • 你能给我举个例子吗?
  • 您的要求是什么
  • 亲爱的米纳克希!我需要将我的“checkout/cart_sidebar”模板分配给 php 脚本中的变量。我需要将其发送到我的浏览器/javascript 以进行进一步操作)
  • 除了只喜欢降低利率的人之外,是否有任何 Magento 专家知道如何获得它))大声笑

标签: magento checkout


【解决方案1】:

在你的控制器中,你可以尝试这样的事情:

    $block = $this->getLayout()->createBlock('checkout/cart_sidebar');

    $block->setTemplate('checkout/cart/sidebar.phtml');

根据您的配置(配置 -> 结帐 -> 购物车侧边栏),您可以使用

渲染模板
    $block->toHtml();

如果您使用自定义模板,则可以忽略配置值,以便随时呈现。

【讨论】:

    【解决方案2】:

    布局 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'
         )
    
    ?>
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2011-11-19
      • 2011-09-29
      • 2020-01-03
      • 2012-03-15
      • 1970-01-01
      • 2012-07-04
      • 1970-01-01
      • 2015-02-23
      • 2012-08-21
      相关资源
      最近更新 更多