I have a helper with this method to get the items in a customer's cart

public function getCartData()
    //Get cart DATA
    $quote = Mage::getSingleton('checkout/session')->getQuote();
    $cartItems = $quote->getAllVisibleItems();
    $items = '';
    foreach ($cartItems as $item) {
        $items .= $item->getId() . " ";
    return $items;

But what I want to do is replace this line

$items .= $item->getId() . " ";

With an instance of template/checkout/cart/sidebar/default.phtml

How would I go about this? The method is being called in an ajax controller. I want to update the user's cart without a page refresh, but it needs to be formatted.

1 Answer 1


You can create blocks on the fly and fetch the HTML

Simple example:

    $tempBlock = Mage::app()->getLayout()->createBlock('core/template')

    $items .= $tempBlock->toHtml();

This is not complete as it misses the item information and I just used the core/template which is not the usual on for this template.

But I hope you get the idea?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.