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:
- Create a theme “child” that extends from another theme “premium_template”
- Within the child folder create:
- Populate it with:
<?xml version="1.0"?> <theme> <parent>my_package/premium_template</parent> </theme>
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.
- Create another theme “grand_child” that extends “child”
- Within the grand_child folder create:
- 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
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?