I'm trying to add product blocks to the noitems [your cart is empty] page in magento 1.9
I kind of figured it would be something like:
<checkout_cart_noItems>
<reference name="content">
<block>whatever</block>
</reference>
</checkout_cart_noItems>
But it's not, comparing to the default checkout.xml layout file I see that a template is set:
<action method="setEmptyTemplate"><value>checkout/cart/noItems.phtml</value></action>
How can I add my product blocks to the noItems.phtml file in my local.xml?
Best Answer
The
noItems.phtml
template is rendered by the same block as the normalcart.phtml
template, depending on the number of items in the cart.But it can contain a child
checkout_cart_empty_widget
, which is only rendered on thenoItems.phtml
cart. It does not exist in the default theme and is an empty container in the default rwd theme (used to attach widgets to it).If you are using the rwd theme or a theme that is based on the rwd theme, you can add additional blocks to it:
If not, you can add it, the same way as it's done in the rwd theme:
Add block below "No items" message:
This block is rendered before the "You have no items in your shopping cart." message.
If you want to add something below this message, there is another child, called
shopping.cart.table.after
, which is not created anywhere in the default themes as far as I can see, but it is also rendered incart.phtml
of the rwd theme (not the default theme), so if you want to use this and be compatible with different themes, better create a custom product block that is only displayed if the cart is empty:The layout XML should be like this, to add the referenced but non-existing container block and add yours as a child: