Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How could I add CSS and JS references to the Cart Page only? 
 
adrianalexan
Jr. Member
 
Total Posts:  3
Joined:  2012-11-11
 

There are countless articles about customizing the content and layout of the /checkout/cart page, however, I didn’t find one about how to add custom CSS or JS references to this page only, preferably in a “cleaner” manner, such as:

<reference name="head">
 <
action method="addCss"><stylesheet>mycustom.css</stylesheet></action>
</
reference>

Thank you for pointing out a useful reference on this particular matter!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lyonscg
Sr. Member
 
Avatar
Total Posts:  173
Joined:  2009-11-13
Chicago IL
 

The code you posted works for most pages, but because method “addCss” isn’t available to the checkout.xml file by default that won’t work for the cart. In fact it’ll actually generate an error.

I haven’t looked into this too much, but in theory you could extend a few core classes in a custom module to get Magento to first recognize that method in checkout.xml and then to add the css. I think I found my next weekend project =)

Out of curiosity, why do you want a specific CSS file for the cart? What would the benefit be over keeping the code in the same CSS file as the rest of the site?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Magestore
Mentor
 
Avatar
Total Posts:  1015
Joined:  2009-08-07
Viet Nam
 

Hi adrianalexan,

If you only want to add a custom css for checkout cart page, you can go to file:
..\app\design\frontend\base\default\layout\checkout.xml (or the layout file that is corresponding to your theme)
After that, add your css file to checkout_cart_index tag:

<checkout_cart_index translate="label">
 <
reference name="head">
  <
action method="addCss"><stylesheet>mycustom.css</stylesheet></action>
 </
reference>
...
</
checkout_cart_index>
Hope this helps.

Best Regards,
Magestore

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagikSwapna
Sr. Member
 
Total Posts:  97
Joined:  2010-12-14
 

Hello,

Try following code to add css and js in your cart page.

<link rel="stylesheet" href="<?php echo $this->getSkinUrl(); ?>css/yourcss.css" type="text/css" />
<
script src="<?php echo $this->getSkinUrl(); ?>js/yourjs.js" type="text/javascript"></script>
Hope this will help you.
 
Magento Community Magento Community
Magento Community
Magento Community
 
pakerjon
Jr. Member
 
Total Posts:  1
Joined:  2013-02-25
 

informative post.. thanks for sharing it..

 
Magento Community Magento Community
Magento Community
Magento Community
 
jasmine78888
Jr. Member
 
Total Posts:  1
Joined:  2013-05-02
 

it is really nice post i like this info i appreciate this post keep it up.........:dance:

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top