Templates inside skins are responsible for the HTML content of what will be displayed to the user. You can choose the template of the page you are interested in and make any changes to it.

Managing templates

Working with templates is done from the "Templates" tab of your skin. In this section, you can add system template files to your skin and modify them as you wish. If a template file is present in the skin, the system will use it and not the system version.

  • To add a template to your skin, find it in the list and click the "Add" button.
  • You can edit the template by clicking the "Edit" button through the built-in editor.
  • You can download the template by clicking on its name, change the content and upload it manually via FTP to your skin tpl folder.
  • You can also add a template with an arbitrary name for use in your own modules.

The most useful templates:

  • home - home page landing.
  • login - login, registration and password recovery form.
  • header - heading part of the site, including top and side menu.
  • footer - bottom part of the site with copyright and JS-code.

We recommend not even getting into other templates and limiting yourself to changing these. Leave the inner part of the site unchanged by simply changing the class names through macros. Otherwise, you will have to check changes in your own and system templates with each new build. New builds appear from once every few days to several times within one day.

Template syntax

The built-in templating engine is somewhat reminiscent of Smarty, its idea is based on the phpBB2 templating system. The template engine supports the insertion of variables, repeating blocks and conditional blocks.

Inserting an ordinary variable:

{myvar}

Inserting a macro:

{tpl:macroname}

Inserting repeating blocks is done with <!-- BEGIN xxx --> at the beginning of the block and <!-- END xxx --> at the end. Inserting variables inside the block is done through a dot: {xxx.yyy}. If nested blocks are used, the entire chain of blocks must be specified in the variable: {xxx.yyy.zzz.aaa}.

<!-- BEGIN offer -->
  {offer.name}
  <!-- BEGIN goal -->
    {offer.goal.name}
  <!-- END goal -->
  {offer.description}
<!-- END offer -->

You can also use conditional statements in a template. They always check the value of only one variable, you cannot make complex conditions. The conditional block is inserted using <!-- IFSET xxx --> at the beginning of the block and <!-- ENDIF --> at the end, block < code><!-- ELSE --> is also provided. Several conditional statements are available:

  • IFSET xxx - if xxx is true
  • IFNOT xxx - if xxx is false
  • ELSE - otherwise
  • ELSEIF xxx or ELIF xxx - otherwise if xxx is true
  • ELSEIFNOT xxx or ELNO xxx - otherwise if xxx is true
  • IFTPL xxx - if macro xxx is true
  • IFNTP xxx - if macro xxx is false

Examples of conditional statements:

<!-- IFSET hasnews -->
{newstext}
<!-- ELSE -->
{nonewshere}
<!-- ENDIF -->

Useful macros

When working with templates, it will be convenient for you to specify paths to resources using macros. So these paths will be relevant when moving the skin to another folder.

  • {tpl:skin} - skin folder, for example mystyle.
  • {tpl:skinpath} - skin folder path, for example /skin/mystyle, no slash at the end.
  • {tpl:skincss} - CSS files path, for example /skin/mystyle/css, no slash at the end.
  • {tpl:skinjs} - JS files path, for example /skin/mystyle/js, no slash at the end.
  • {tpl:skinimg} - images path, for example /skin/mystyle/img, no slash at the end.

Using templates in code

If you are creating your own module, you will need a few simple commands to work with templates.

The template is included as a named document entity - part. Most often, the name body is used for the body, which we will give in the examples. The header uses the name header, the footer name is footer. You can use any name for the part you're working with, just make sure it always comes as the first parameter to the function.

Preparing the template for work:

$core->skin->load( 'body', 'my-template-file' );

Specifying the main parameters with a key-value array:

$core->tpl->vars( 'body', [ 'foo' => 'bar', 'peace' => 'deathz' ] );

Adding a block, parameters - by key-value array:

$core->tpl->block( 'body', 'blockname', [ 'myvar' => 'myvalue' ] );

Render of the specified part:

$core->tpl->output( 'body' );

Like a fish in water

Templates from TPL files are converted into pure PHP code. In theory, you can use PHP in source templates and it will even work. We do not recommend doing this, but we do not forbid you to enjoy the process.

Inserting the {myvar} variable after rendering looks like this:

<$= $_data['myvar']; ?>

You can refer directly to $_data['myvar'] in any part of the code, this variable is active and is defined everywhere within the template.

Inserting a block variable {blockname.myvar} after rendering looks like this:

<$= $blockname['myvar']; ?>

You can access the variable $blockname['myvar'] only within the specified block, it is not defined outside of it.

The $_data array contains all template engine data, including nested blocks. The keys of the main variables correspond to their names in the template, the keys of the blocks contain a dot at the end.

$_data = [
 'myvar' => 'foo',
 'blockname.' => [
   'myvar' => 'bar',
   'nestedblock.' => [
      'onemore' => 'variable'
   ]
 ]
];

Manual implementation of templates is not recommended. But it looks tempting.