2

In checkout.xml I see

<action method="setCartTemplate"><value>checkout/cart.phtml</value></action>
<action method="setEmptyTemplate"><value>checkout/cart/noItems.phtml</value></action>
<action method="chooseTemplate"/>

I am trying to have a block only show up when there are items in the cart but not when its empty. How do I accomplish this?

3

Ad your block normally, and wrap your display html in a conditional, checking for cart items.

This will work,

Mage::helper('checkout/cart')->getCart()->getItemsCount();

without having to rewrite any core blocks, or even creating your own block.

Your phtml block could then just be core template block, unless you need more cart logic in your template, then you should extend the core cart abstract block from your own block (Mage_Checkout_Block_Cart_Abstract) which will give you access to all the core cart methods.

Then just add your block to the xml, and it will only output it's code if there are items.

Depending on what your intended display is, you can add your block as a child of these core block lists, then you don't need to change the base cart.phtml file to echo out your block

<block type="core/text_list" name="checkout.cart.top_methods" as="top_methods" translate="label">
                    [ add your block here ]
                </block>

<block type="core/text_list" name="checkout.cart.methods" as="methods" translate="label">
                   [ add your block here ]
                </block>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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