719-286-0751 [email protected]

Magento 1.9 Multiple Theme Inheritance

Magento 1.9 Multiple Theme Inheritance

The release of the Magento 1.9 version has prompted a change in frontend design patterns for Magento developers.

No longer do you have to rely on the “default” package to provide some type of re-usability within themes. The new pattern allows for “inheritance” between themes. You can explicitly identify a parent theme from within a child. However, what many people don’t know is that this inheritance is infinite – meaning, we can inherit multiple times.

An Example Use Case

Let’s say I’m developing several custom themes for my website. I start with a premium template as my “base” theme. Given that the creator of this template might release an update in the future, I’d prefer to “inherit” from this theme in a way that allows me to upgrade it seamlessly.

Following the theming guidelines from the 1.9 rwd guide I can easily accomplish this:

  1. Create a theme “child” that extends from another theme “premium_template”
  2. Within the child folder create:
    1. etc/theme.xml
    2. Populate it with:
      <?xml version="1.0"?>
      <theme>
          <parent>my_package/premium_template</parent>
      </theme>

1_inheritance

There we go! I can now copy layout files, templates, etc from premium_template -> child – changing only what I need.

However, let’s say that this website needs a holiday theme. It’s not uncommon to “spice things up” with some seasonal images / styling around Christmas. You might be thinking “Crud, do I need to copy everything from my child theme over to a new theme folder, and then inherit from premium_template?” – the answer is no, you can simply inherit again from the child theme.

  1. Create another theme “grand_child” that extends “child”
  2. Within the grand_child folder create:
    1. etc/theme.xml
    2. Populate it with:
      <?xml version="1.0"?>
      <theme>
          <parent>my_package/child</parent>
      </theme>

**Notice – Observe that we extended child this time instead of premium_template

grand_child

 

Once again, it’s that easy! We can now copy only the files we want to change from child -> grand_child.

Need help building a Magento theme with multiple inheritance?

We’ve had a lot of experience customizing Magento here at Cadence Labs. If you need help, head over to the Cadence Labs contact page, or email us at [email protected]

Alan Barber is the Lead Web Developer at Cadence Labs and a Magento Certified developer.

 

 

1 Comment

  1. China

    That’s not just logic. That’s really senblsie.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Install our webapp on your iPhone! Tap and then Add to homescreen.
Share This