Get Free Audit

Themes in Magento. Part V (Magento Certified Developer Exam)

Feb 14, 2013

323 Mishel Soiko

Themes in Magento. Part V (Magento Certified Developer Exam)


We have used this class many times to get theme files but have not checked what is inside yet. So, let’s see if there is anything interesting there to learn.

These is where we previously met this class:
1.    Mage_Core_Model_Layout_Update :: fetchFileLayoutUpdates()
2.    Mage_Core_Model_Layout_Update :: getFileLayoutUpdatesXml()
3.    Mage_Core_Controller_Varien_Action :: addActionLayoutHandles()
4.    Mage_Core_Model_Resource_Layout :: fetchUpdatesByHandle()
5.    Mage_Core_Block_Template :: getTemplateFile()
6.    Mage_Core_Block_Abstract :: getSkinUrl()

Here I have put down the functions which have been used in:

1. 2. 3. 4.

Mage_Core_Model_Design_Package :: getArea() , as well as getPackageName() and getTheme($type)

These are some of the described constants:
DEFAULT_AREA         = ‘frontend’;
DEFAULT_PACKAGE = ‘default’;
DEFAULT_THEME      = ‘default’;

  • getArea

The focus of our attention are the ‘frontend’ themes. As we see the constant DEFAULT_AREA  already has the required value. If need to change it, there is the function setArea($area), which can be launched, for example, from observer: “controller_action_predispatch ”.

  • getPackageName

Here we see that if Package has not been installed yet, there is launched the function setPackageName();  which we worked with in the first part of the article. It was a bit modified there, but originally it looks like this:

The function sets the package name to search for theme files in future.

– If the function argument has been specified then the package name is defined by the argument value.
– Otherwise it will check for Exeption via the function _checkUserAgentAgainstRegexps . For instance, we can set names of mobile devices and a package with a mobile theme. All this will be checked and if some of the listed devices are found as being used, then the name of  the specific mobile theme package gets defined.
– If using the above parameters we still do not get the name, then take it directly from getStoreConfig(‘design/package/name’).

After the name has been defined, the existence of the relevant folder is verified. If the folder does not exist, then the default name is set.

  • getTheme

The same as in the previous 2 functions, here it is verified if the current theme has been already defined.

Specific theme folder name can be individually set for several types: “locale”, “layout”, “template”, “skin”. There is one more type which sets default values for all ”default”s above.

Taking a look at the function getTheme it is possible to describe which of the settings have higher priorities.

– At the end we see that if Exeption has been defined then the function replaces previous values and returns the Exeption value.
– Primarily it is verified if the theme value has been previously defined.
– If theme has not been defined yet, then next comes the verification for the relevant type in getStoreConfig(‘design/theme/’ . $type)
– If nothing has been defined there as well, then the function getTheme(‘default’) is called.
– In case still noting is found, then just use the constant self::DEFAULT_THEME

As you see, all three functions verify if the value has been already defined and yet there hasn’t been any single access to the admin settings under System / Design. While in the very first part of the article it was said that exactly these settings have maximum priority ( not taking into account the influence of Exception for Theme and the function we rewrote in the first part which prioritized Exeption for Package). The conclusion is obvious. During the web page initialization there is code which primarily influences the values of the class variables.

Where is this code located?

Mage_Core_Controller_Varien_Action  :: preDispatch()

So the default area has been set.

When describing load, I will combine some of the functions.

Now all is in its place.


We load the design changes saved in the admin panel under System / Design and in case there were any  – set Package and Theme values  inside the object Mage_Core_Model_Design_Package. Now it is possible to use the function getTheme, which will return the theme specified under System / Design or use admin panel settings System / Configuration / General /Design. This is what developers use when launching the file initialization and translating the translate.csv file, which is defined only for the current theme.


Mage_Core_Model_Design_Package :: getTemplateFilename ($this->getTemplate(), $params);

There are 3 similar functions used to get a link to a specific template, locale or layout file.\

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

This makes sense, because the path to the file differs with one folder only. As an example lets try to get a template file path.
$params[‘_type’] = ‘template’;

The function updateParamDefaults($params) fills the array $params with additional values such as:

And then it is only needed to put them into the line in the right order. But the function _fallback() does not do only that. Before exposing the code of the function, let us take a closer look at the parameters, which are passed inside.

  • $file – is a file template used in layout. For instance ‘catalog/product/view.phtml’
  • $params – an array of this type:

This is the data of our current theme, type of the file and the object of the current store. This would be enough if there was no theme file inheritance. For this reason there exists the following passed parameter.

  • 3-rd parameter: Array. I will show the values the same way I did in the first part of the article.

In our case we get an array with the following values:

Checking all the values of the array $fallbackScheme. combining the content with the array $params. Checking for and verify the received file and if not found – move on to the next element $fallbackScheme. If we reach the end of the function, this means our template has not been found anywhere. Then there is the last option left:

$params[‘_package’] = self::BASE_PACKAGE; // base
$params[‘_theme’] = self::DEFAULT_THEME; // default

Primarily Magento will check for the template here app/design/frontend/air/christmas/catalog/product/view.phtml
If the template is not found, will continue here app/design/frontend/air/air/catalog/product/view.phtml
and then, if necessary, here app/design/frontend/air/default/catalog/product/view.phtml
If no template found it will return this variant app/design/frontend/base/dafault/catalog/product/view.phtml


Mage_Core_Model_Design_Package :: getSkinUrl($file, $params);

Here it is the same as in point 5 –  just made as a separate function

Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *