HTML layouts

Your design is likely to include many different layouts that will get included between the header and footer files. In Unicity CMS, these are created in HTML, using .tmpl files.

These template files sit within the /templates folder, and would be shared between any templates you have (such as the standard "default" template).

Each template should be numbered, with positive integer numbers, e.g. template1.tmpl.

You do not need to use sequential numbers, it may be beneficial to use unique numbers instead, that allows templates to be used in multiple projects.

Each template tmpl file requires a corresponding template definition file, which is a PHP file that defines the editable areas, e.g. template1.php.

Merge tags

Within your template definition file, you will specify a number of editable regions. Each one needs to be given a unique (within that template) merge tag.

This can be any alphanumeric string. For best results, use common names where the same elements exist in multiple templates, as this allows templates to be switched without mapping content.

For example, if a merge tag has been created called HeaderContent, you would insert this into the template using the shortcode %contentHeaderContent%.

Including partial templates

To allow code to be shared between templates, you can include partial templates into your main page layout templates.

It is recommended that you name these templates with a different convention than the page layout templates to avoid confusion.

Lets assume you have a template partial called "partialheader.tmpl", that you want to include into template1. This would be placed in the /templates folder along with your template1.tmpl file. To include it in template1.tmpl, use the following code:

%include:partialheader%

Includes are processed before any other template logic is applied.

Conditional code in templates

There are two ways you can use conditional code within a tmpl template.

1. Conditional HTML or Unicity Tags

If you just want to conditionally display a piece of HTML, a merge tag, or an include, then this simple IF condition will be what you'll need.

%if:CONDITION%
	Hello world
%endif%

2. Conditional PHP

This is a more powerful form of conditional code, as you can do any PHP processing within the condition. 

%ifphp:CONDITION%
	print("HELLO WORLD");
%endif%

For both types of conditional code, the CONDITION must be replaced by a PHP formatted condition. For example

%if:$contentHeaderType == "Large"%

Merge tags should be in their PHP variable form within conditions.

Simply using PHP in TMPL files 

While TMPL files are designed to contain HTML, using a PHP TRUE condition you can use any PHP code as well:

%ifphp:TRUE%
	print("HELLO WORLD");
%endif%

Repeatables

Unicity CMS implements a facility known as "repeatables" that allow a number of fields to be grouped and repeated on a page as many times as an editor wants. This is ideal for list type pages, block style navigation pages, or pages created using horizontal strips.

Fields within repeatables are defined in the same way as any other field, however they are grouped within a parent field.

If your repeatable is called block you wrap your HTML in repeatable merge tags to create the repeatable loop.

%repeatable block%

Loop HTML here

%endrepeatable%
A repeatable may contain HTML, merge tags, conditions and PHP using the above techniques.

Using a combination of a select box field with a condition can allow a repeatable to be used for different types of content switching the output based on the value of the select box.