Define and describe the use of themes in Magento
How can you use themes to customize core functionality
Themes are not really intended to modify core functionality, so if you need to make some in depth modification, you better try to create some custom extension to do so.
Throught themes you can anyway modify some behaviours, specially in two ways:
- Modifying layouts of pages you can modify or add new blocks to any page on your Magento Store.
- Modifying core templates by overriding them you can modify some core behaviours as well.
How can you implement different design for different stores using Magento themes
In Magento you can install as much themes as you need. Also you can group themes inside of packages to take advantage of inheritance by defining one default theme and a number of child ones.
Let’s say you have to stores, then there are two common situations:
If you want to mantain ‘almost’ the same design between them, just changing some colors, logos o with slight changes of the layout, then your best bet is to have one package with one default theme, and two child themes with the needed changes to it.
If you want two completely diferent design for your stores, then you shold have two differente theme packages, each one with one default theme, and use child themes only for stationery/temporary design changes.
In which two wayss you can register custom themes
Once you have your theme developed, you need to tell Magento which store and when you want to use your theme.
If you want your theme to be used ‘always’ as your store theme, you may tell Magento to use it from System => Configuration => Design.
There you can define your default package and theme for each of your Magento stores.
Also, for temporary/seasonal design changes you may tell Magento to use a particular theme between to dates. You can define that in Magento at System => Design.
Any of two methods, allow you to register your custom theme with Magento.
Define and describe the use of design packages in Magento
Design Packages in Magento, allow to group themes in a way that you can define some kind of inheritance between their files.
What is the difference between package abd theme
A common way of taking advantage of this is that you may define a default theme for the package and also a number of child themes that inherit from it.
When a new child theme is defined you may override any file or behaviour from the default theme. That way your may have, for example, a seasonal Christmas theme that is only active during that period. This theme has only slight changes to your ‘rest of the year’ theme so its a clear example of the advantage of inheritance.
Also if you have several store views (languages) for the same store you may have different child themes for each one, and override images or other default contents.
What happens if the requested file is missed in your theme/package
If a particular file is missed in a theme, there is are some fallback themes and packages where Magento will try to find it.
- First location in the fallback chain is the default theme of the current package.
- Second location is the base package default theme which exists in a stock Magento install.
You can also define a third point in the middle of these by defining a custom default theme (with a different name than ‘default’) in your admin panel.
Describe the process of defining template file paths
Which kind of paths (absolute or relative) does Magento use for templates and layout files
Magento always use relative paths to be able to make fallback access to other themes and packages.
How exactly can Magento define which physical file correspond to certain template/layout to use?
Magento uses the class Mage_Core_Model_Design
to find the exact file name of a template or layout file to use.
All the requests go through following method:
public function getFilename($file, array $params) { Varien_Profiler::start(__METHOD__); $this->updateParamDefaults($params); $result = $this->_fallback($file, $params, array( array(), array('_theme' => $this->getFallbackTheme()), array('_theme' => self::DEFAULT_THEME), )); Varien_Profiler::stop(__METHOD__); return $result; }
And the magic happens in the call to _fallback
which looks for the specified filename, in different paths of the magento design folder. In a typical Magento store, the fallback list may be something as follows:
/app/design/frontend/<your package>/<your theme>/<some file> /app/design/frontend/<your package>/defaulu/<some file> /app/design/frontend/base/default/<some file>
This example is for a design file (like a template) but a similar list is used for a skin one.
Which classes and methods need to be rewriten in order to add additional directories to the fallback list?
As told in the previous section, you should override Mage_Core_Model_Design_Package
and at least the following methods:
public function getFilename($file, array $params) {} public function getSkinUrl($file = null, array $params = array())
In that methods, you see an array like the following, which defines the fallback list:
array( array(), array('_theme' => $this->getFallbackTheme()), array('_theme' => self::DEFAULT_THEME), ));
Hey! Qué opinas sobre el artículo?