开发者

How to load a magento view (.phtml) file from a controller

开发者 https://www.devze.com 2023-03-23 01:54 出处:网络
Im trying to load a rendered version of the cart sidebar, which i intend to load via ajax... I\'ve been searching around alot and it seems like the best approach is to create a custom module which wil

Im trying to load a rendered version of the cart sidebar, which i intend to load via ajax... I've been searching around alot and it seems like the best approach is to create a custom module which will handle all my ajax request. I have created a custom module and everything seems to be working however when I display the sidebar.phtml it is not rendered properly. I开发者_开发技巧t displays as if there is nothing in the cart. (im assuming its just trying to reading the file without using any session info). I've search a bunch but nothing seems relevant to what I'm trying to do.

This is the code im using in my custom controller to load the phtml file which is essentially a copy and past of the checkout/cart/sidebar.phtml file.

$layout = $this->loadLayout();


$block = $this->getLayout()->createBlock(
'Mage_Core_Block_Template',
'PPWD_Custom',
array('template' => 'custom/custom.phtml')
);
echo $block->toHtml(); 

Thanks


The problem is in incorrect block type. Instead of Mage_Core_Block_Template you should use Mage_Checkout_Block_Cart_Sidebar. Like this:

$this->getLayout()->createBlock(
    'checkout/cart_sidebar',
    'PPWD_Custom',
    array('template' => 'custom/custom.phtml')
);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号