2.10. Master templates

Starting from 1.1.0, OPT supports master templates. They are automatically loaded, when any of the website templates has changed and needs to be compiled. Some instructions, like binds and bindEvents exist only during the compilation time and there is no way to autoinclude them with include. The master template is the only solution to create an universal repository of them for all the templates.

Which template is the master, the script programmer defines with optClass::setMasterTemplate() method. The programmer may set more than one master templates for the application.

Take a look at the example. You do not have to declare all the content for the tree instruction - the parts can be loaded from the bind snippets. Using a master template, we create a universal tree layout for all the website:

Example 2.71. A master template

{bindGroup=universalTree}
{bind=opening}
<li>{$item.title}<ul>
{/bind}
{bind=leaf}
<li>{$item.title}</li>
{/bind}
{bind=levelclose}
</ul></li>
{/bind}				
{/bindGroup}

Now, everytime we want to put somewhere a tree, we write:

Example 2.72. Universal tree use

<ul>
{tree=sometree}
	{use group="universalTree"/}			
{/tree}
</ul>

If this template needs to be compiled, the compiler will load a master template with the universal tree structure so that the template could use it.