Skip to the content
Documentation

How templates work

No ratings yet

A template is a text file, usually HTML, with template code between curly brackets. Exponential renders templates to build every page it sends: the HTML around the content, the content itself, the lists, menus and forms. Templates live in designs; a siteaccess uses a chain of designs, and the first design that has a template wins.

A small template that prints the current time:

<h1>Time machine</h1>
<p>The current time is: {currentdate()|l10n( 'time' )}</p>

Everything outside the curly brackets is sent as it is. Inside them, currentdate() is a template operator that returns a Unix timestamp, and the pipe hands that value to the l10n operator, which formats it for the current locale. The language is described in The template language.

Exponential has three template engines in 6.0.15: its own template language (files ending in .tpl), Smarty 5 (.stpl) and Twig 3 (.twig and .html.twig). This chapter uses .tpl, the language of every shipped design and extension; the other two are described in Template engines.

How a request becomes a page

Every request runs one view of one module, for example the full view of a node through content/view, or user/login. The view renders its own template and returns the result in an array. Exponential then renders the main template, the pagelayout (pagelayout.tpl), and passes that array to it as $module_result. The pagelayout prints the view's HTML where it writes:

{$module_result.content}

So a page is at least two templates: the pagelayout, which holds the html, head and body elements, the menus and the footer, and the view template, which holds the content. Both usually include further templates. The keys of $module_result are listed in the module result reference.

Node templates and system templates

The templates a view renders fall into two groups:

  • Node templates show a content node: node/view/full.tpl, node/view/line.tpl and the other view modes. They receive the node as $node, and override rules can pick a template by class, node, section, depth and many other conditions.
  • System templates show everything else: the login form (user/login.tpl), the search page (content/search.tpl), the basket (shop/basket.tpl). Each view sets its own variables.

Where to go next

In this section

Contributors

Comments (9 historical)

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

  1. how to specify content type of template?

    vytis ·

    Is anywhere described, how to specify content type of template?

    1. Re: how to specify content type of template?

      hinroen ·

      Nope.

      1. Re: Re: how to specify content type of template?

        Gaetano ·

        By default view templates use the standard html content-type.
        To set a different one, the easiest ways is to take advantage of the "set" view of the "layout" module

  2. Gibberish and Gobbledegook

    Mr LinguaFranca ·

    People should be forewarned at an early age that something tragic happens to people if they become computer programmers. They lose the ability of simple expression.
    "A node template gives access to a variable ($node) which contains information about the actual node that is being viewed. Depending on the view that was called, a system template typically gives access to several variables. A template override rule makes it possible to display custom templates in specific cases."
    What on earth is this mumbo-jumbo?

    1. Re: Gibberish and Gobbledegook

      Elkin Taharon ·

      Well, i don't know exponential, but i think that this concept is also manage by drupal CMS, the general idea is that u have a php var called "$node", with all the node information (Title, content and so on), the information in the "$node" change from one view to another (i.e. if you are calling an admin view, it maybe contents some private information as the author's email or something like that, in this case $node will contain a $node->email attribute).
      So if you want to display the title in some part of the template, you just need to use something like "$node->title"
      Please correct me if i'm wrong... is my first day in ez content and my English sucks a little :p

  3. Connection between page and its template

    Dianne Pearson ·

    How to I find out which template a page is using? Our site is managed by a design company and they create templates for me. When I need changes I have to request them. How can I determine which template is being used for specific pages?

    1. Re: Connection between page and its template

      rainer ·

      you can enable some debugging in your
      siteaccess/xxx/site.ini.append.php .
      [TemplateSettings]
      Debug=enabled
      ShowUsedTemplates=enabled
      Obviously not recommended on livepages

    2. Re: Connection between page and its template

      Massimiliano Bariola ·

      Hi Dianne,
      jsut as rainer said, but you also can add the DebugByIP directive so that the debug will be visible only to your defined IP set.
      Ciao

  4. The graphics on this page are broken

    Bill Winett ·

    The graphics on this page are broken.

Comments

Add a comment

Comments are read by a moderator before they appear.