How templates work
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
- Find out which design your siteaccess uses and where its templates are: Designs and design order.
- Show a class or a node with a template of its own: The template override system.
- See which template printed which part of a page: Debugging templates.
In this section
- Node templates Node templates in Exponential 6: view modes, node/view/<mode>.tpl, the $node variable, node_view_gui and override templates per class.
- System templates System templates in Exponential 6: the templates of module views such as user/login.tpl and content/search.tpl, and how to customize them in your own design.
- Connection between page and its template / Template basic... Exponential Documentation
- Gibberish and Gobbledegook / Template basics / Templates ... Exponential Documentation
- how to specify content type of template? / Template basic... Exponential Documentation
Contributors
- Balazs Halasy
- Geir Arne Waaler
- vytis Commenter
- hinroen Commenter
- Gaetano Commenter
- Mr LinguaFranca Commenter
- Elkin Taharon Commenter
- Dianne Pearson Commenter
- rainer Commenter
- Massimiliano Bariola Commenter
- Bill Winett Commenter
- Graham Brookins Updated Maintainer
Comments (9 historical)
Written by readers of the earlier documentation sites, kept as they were.
how to specify content type of template?
vytis ·
Is anywhere described, how to specify content type of template?
Re: how to specify content type of template?
hinroen ·
Nope.
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
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?
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
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?
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
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
The graphics on this page are broken
Bill Winett ·
The graphics on this page are broken.