Skip to the content
Documentation

The template language

No ratings yet

The template language of Exponential (files ending in .tpl) mixes text, usually HTML, with template code between curly brackets. The template system reads everything between { and } as code; everything else is sent as it is.

<h1>{$node.name|wash}</h1>
{if $node.children_count|gt( 0 )}
    <p>{$node.children_count} pages below this one.</p>
{/if}

Inside the brackets you find four kinds of code:

  • Variables, written with a dollar sign: $node, $node.name. See Variable usage and Variable types.
  • Operators, which take a value and return one, chained with a pipe: $node.name|wash, $count|gt( 0 ). See Functions and operators.
  • Functions, which do something and often have a closing tag: {if}...{/if}, {foreach}, {include}, {def}. See Control structures.
  • Comments: {* ... *}. See Comments.

Variable names are case sensitive: $Title and $title are two variables.

Curly brackets in the output

Because { starts template code, text that contains curly brackets, such as JavaScript or CSS, must be put inside {literal}; the template system does not read what is between {literal} and {/literal}:

{literal}
<script>
    function focusSearch() { document.getElementById( 'search' ).focus(); }
</script>
{/literal}

A single bracket is written with the functions {ldelim} and {rdelim}, which print { and }. Inside a quoted string, a closing bracket is escaped with a backslash: {'{ inside \}'} prints { inside }.

Better still, keep scripts and styles in files of the design and load them with the ezjscore functions or the design settings, as the pagelayout of the standard design does (see The pagelayout).

In this section

The language in full depth, from its lexical structure to the compiler, is in the template language manual. Developers who know Smarty or Twig can write templates in those languages instead; see Template engines.

In this section

Contributors

Comments (1 historical)

Written by readers of the earlier documentation sites, kept as they were.

Comments

Add a comment

Comments are read by a moderator before they appear.