Magento fall-back on theme

2019-09-06 21:25发布

问题:

I installed a theme on my Magento instance, which I'd like to further customize. I imagine that similar to Magento's fallback hierarchy where my theme can fall-back on default packages, I should be able to structure my directories in such a way that I can make changes to particular parts of my theme by maintaining a similar structure and relying on a fall-back.

So here's my question: How can I develop a child-theme of another theme, with the fall-back setup this way? Is this performed by structuring directories a certain way, or is this performed some other way?

Thanks!

回答1:

If you are using Magento EE 1.14 or CE 1.9 than you can utilize the method described here to make a child-theme: http://www.magentocommerce.com/knowledge-base/entry/ee114-ce19-rwd-dev-guide http://alanstorm.com/magento_parent_child_themes

Important: It's very important you have a theme.xml in the app/design/frontend/custompackage/customtheme/etc directory with exactly the contents shown. Failure to configure theme.xml correctly prevents Magento from loading your theme.

You must create your theme structure as noted and place a theme.xml file within it, containing the following code:

Magento CE:

<?xml version="1.0"?>
<theme>
  <parent>custom_package/custom_parent</parent>
</theme>

Magento EE:

<?xml version="1.0"?>
<theme>
  <parent>custom_package/custom_parent</parent>
</theme>

For versions EE v1.8+ or CE v1.4+, you should reference here: http://www.magentocommerce.com/knowledge-base/entry/magentos-theme-hierarchy

Heirarchy is as follows:

  1. app/design/frontend/custom_package/custom_theme/ && skin/frontend/custom_package/custom_theme

If not found, then

  1. app/design/frontend/custom_package/default && skin/frontend/custom_package/default

If not found, then

  1. app/design/frontend/base/default && skin/frontend/base/default

If not found, then

  1. throw error

Based on this you could place your default theme at custom_package/default and your child-theme at custom_package/custom_theme, all files not found at custom_package/custom_theme would then fall-back to custom_package/default. Whatever is missing is sought at the next level of hierarchy.

Set your Package and Theme at Admin > System > Configuration > Design



回答2:

Magento's fallback scheme is pretty simple to work with. You can select the package, theme, and default theme by navigating in your magento admin to System > Configuration > Design

Magento starts loading templates / layouts from

app/design/frontend/{SELECTED_PACKAGE}/{SELECTED_THEME}

if it cant find the file its looking for in there, it will look in

app/design/frontend/{SELECTED_PACKAGE}/{SELECTED_THEME_DEFAULT}

and failing that it will look in

app/design/frontend/base/default

So my recommendation to you is install your theme as the default theme, and put your customizations into your selected theme folder. Of course this fallback scheme can be used in a lot of different ways depending on what your needs are, but I've always felt this is the simplest and handles most use cases.

app/design/frontend/downloadedTheme/default <- Put your stock files in here

app/design/frontend/downloadedTheme/myCustominzations <- Put your changes in here


标签: magento