Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Template functions, includes and cache blocks

The template language features an application uses most - include, the *_view_gui functions, def/set/undef, foreach, set-block, cache-block with keys and expiry, and how to structure templates of an extension.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/creators/app-creators/template-functions-and-includes.md

On this page

Template functions, includes and cache blocks

This page is for application creators who write the templates of their extension. The template language is described in 6. The template language in ten minutes; this page collects what applications use most.

Contents

  1. Variables
  2. Includes and template parts
  3. The view functions
  4. Loops and conditions
  5. Cache blocks
  6. Structuring an extension's templates

Variables

FunctionUse
{def $a = ...}declare (once per template)
{set $a = ...}change
{undef $a}free; undefine what you defined at the end of a template
{set-block variable=$html}...{/set-block}capture output into a variable

Includes and template parts

{include uri='design:expdemo/parts/item_card.tpl' item=$item show_image=true()}

Parameters become variables of the included template; it is found through the design chain, so sites can override it. Use parts for markup that repeats.

The view functions

FunctionRenders
{node_view_gui content_node=$node view='line'}a node with node/view/line.tpl or its override
{content_view_gui content_object=$object view='embed'}an object
{attribute_view_gui attribute=$node.data_map.body}an attribute with its datatype's template
{attribute_edit_gui attribute=$attribute}an attribute's edit field

Loops and conditions

{foreach $items as $index => $item}
  {if $index|eq( 0 )}<h2>{$item.title|wash}</h2>{else}<p>{$item.title|wash}</p>{/if}
  {delimiter}<hr>{/delimiter}
{/foreach}

{foreach $list as $item max 5 offset 2} limits the loop; {break} and {continue} work as in PHP.

Cache blocks

{cache-block keys=array( $item.id, $current_user.contentobject_id ) expiry=600}
  ... expensive output ...
{/cache-block}
ParameterMeaning
keyswhat the output depends on
expiryseconds; the default is 7200 (two hours, eZTemplateCacheFunction::DEFAULT_TTL); 0 never expires by time
subtree_expirycleared when content below that node or address is published
ignore_content_expirynot cleared by publishing

Data from your own tables is not tied to publishing: set an expiry that matches how stale it may be, or clear the template-block cache when your data changes (Caching in applications).

Structuring an extension's templates

extension/expdemo/design/standard/templates/expdemo/
├── list.tpl            one per view
├── item.tpl
└── parts/item_card.tpl reusable parts
  • One template per view, named after it.
  • Parts in parts/; override templates (per class) in override/templates/.
  • No inline <script> or <style>, no style="": CSS and JS go through design.ini lists (Stylesheets and scripts).
  • |wash on every printed value; |i18n( 'extension/expdemo' ) on every text.
  • Check each with php bin/php/eztemplatecheck.php.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x