Inheritance mechanism of templates
Suppose, your theme is called
my_best_template. The engine asks to use a relative path (path from the root of the theme) to reference the template file -
controllers/content/category_view.tpl.php. This file is firstly searched at the path /templates/my_best_template/controllers/content/category_view.tpl.php, if there isn’t one there, the /templates/default/controllers/content/category_view.tpl.php file is linked. Such behaviour is characteristic of the simplest case of referencing.
Let’s now suppose you have already created the main
my_best_template theme and want to customize it slightly under another title. For this, a new theme is created, for instance,
new_my_best_template. You edit, for example, its CSS styles and/or the main layout of the page and specify that this theme should be inherited from the
my_best_template theme. To enable the inheritance mechanism, in the root directory of the theme, you have to create the inherit.php file in which the array of a chain of templates should be returned, except for the main template (
new_my_best_template) and the
So according to our example we will create the file at the path
/templates/new_my_best_template/inherit.php, the file’s contents will be as follows:
return array( 'my_best_template' );
If you need to have several inherited themes in a chain, enter the titles in the order from the default theme, i.e. from lowest to highest priority. As a result, in this example, the engine will check as follows:
- File’s availability is checked at the path /templates/new_my_best_template/controllers/content/category_view.tpl.php. If the file is found, it is linked at once.
- File’s availability is checked at the path /templates/my_best_template/controllers/content/category_view.tpl.php. If the file is found, it is linked at once.
- And finally, if the file is not found, /templates/default/controllers/content/category_view.tpl.php is linked.
Herewith, if the file is not available in the default theme either, the CMS will show an error and will terminate the work.