December 30, 2009

Magento – Adjust the HTML Body Class of your pages via Layout XML

magento_logoWhen it comes to Magento, I’m mostly a frontend developer. I’ve written some modules – some of which I’m working on sharing with you, public –  but for the most part I stick with it’s core functionalities and just edit the template HTML & CSS files.

As such, I found myself wondering how I could add a new class name to the body tag in the HTML. I at first checked the skeleton template files in the page/ directory of the template; and it just referenced a function. After a little hunting, I found out the correct way to add a new class in Magento – via the layout files.

If you don’t get the layout file concept of Magento, you really ought to look into it. I’m not here to enlighten you about that.

Anyway – you can add new body classes on a per module basis. So let’s say we want to give all the “my account” pages a body class of… account-control. This can be very useful to add a generic style across the board to each account page that is separate from the styling of the rest of the site.

You’d need to find the appropriate module block (I believe it is customer_account) and paste the following code in

  1.  
  2. <reference name="root">
  3.   <action method="addBodyClass"><classname>account-control</classname></action>
  4. </reference>
  5.  

That’s it! Make sure you refresh your cache if necessary, and refresh the account pages after logging into a user account. Check the source – an additional body class of “account-control” has been added!

I wasn’t as specific as I could have been about things in this article; let me know if you have any troubles and I’ll update as necessary for all you n00bs.

Cheers

November 11, 2009

Magento: Approaching, and then Taming, the Beast.

1847195946

Skip reading me, and read Brad Frost’s review of the book to your left.

Magento is a beast. While it continues to pickup accolades for it’s robust e commerce feature set, developers round the world can’t help but find it difficult to work with.

As someone who’s been working with the system for some 6 or so months now, I’m nowhere near an expert. But one thing I know, is that unlike other CMS’, you can’t just jump right into it… not easily at least.

With wordpress, I started learning how to make custom themes + plugins before I really embraced blogging with it myelf; and for the most part this was fine. By the time I started blogging myself, I already knew the ins + outs of the whole system via development.

This just isn’t true with Magento. Even after I had figured out the difficult things like how to customize a theme, or how to make a extensible module, I was still learning about how the system did what it’s supposed to: manage products.

Packt publishing recently put out a new book on Magento, giving it the title of “Beginner’s guide.” If you’re just getting into Magento, or considering making the jump, this might be agreat read for you.

But don’t take my words for it. Read Part 1 of Brad Frost’s review here.

no responses

Best of Blog

  1. Let’s do the kids a favor: HTML as a classroom language
  2. USTORE.js – cross browser local and session storage
  3. Add Facebook Connect to your PHP Web App
  4. Setting up your website on Rackspace Cloud Servers – Manage Your Own Hosting
  5. Tutorial: Using Zend_Captcha_Image

Search if you must