Документация InstantCMS

для администраторов и разработчиков

Инструменты пользователя

Инструменты сайта


Inheritance mechanism of templates

As mentioned in the Introduction, the engine links the template files, css and javascript files along the chain. At minimum, this chain consists of «your theme» ⇒«default theme». So there is no need to copy the unchanged template files from the “default” theme to your theme.

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 default template. 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(

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:

  1. 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.
  2. 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.
  3. 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.

Inheritance extends to the CSS/JS files too, if they were linked via Special Methods. If you do not want to create inherited themes in the future, in the main Template Layout, you should link the possible replaceable files of styles and/or javascript files via $this→getTplFilePath(), $this→getStylesFileName() and $this→getJavascriptFileName() methods.

Back to Section Contents

en/dev/templates/inherits.txt · Последнее изменение: 24.03.2017 00:35 — murlysja