Documentation Menu

1.5 Template Project

The Joomla! Documentation Working Group is running a project to develop detailed reference and tutorial material on Joomla! 1.5 templates.  There is a project page on the documentation wiki where you can see the work in progress and help us by contributing your knowledge.

Who's Online

We have 4 guests online

Help Site License

The Joomla! Help Site content is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution NonCommercial ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Home arrow patTemplate arrow Preface arrow patTemplate Overview

patTemplate Overview PDF Print E-mail


There are five xml tags available in patTemplate that form the building blocks for the templating engine:
  • The tmpl tag
  • The sub tag
  • The link tag
  • The var tag
  • The comment tag

Tag Namespaces

All patTemplate tags must include a namespace which is used to distinguish the patTemplate XML markup tags from regular HTML, xHTML and other XML tags. The default namespace is patTemplate but you my change this as desired by calling the setNamespace method.

$tmpl =& new patTemplate();
// change the namespace to 'cms'
$tmpl->setNamespace( 'cms' );
<!-- using your custom namespace --><!-- using your custom namespace -->
  This is a test of my content management system.

Template Types

Templates are parts of html pages, which can be displayed by the template engine. To identify a certain part of the page as a template, patTemplate uses XML tags to assign a template a unique name and a various attributes (see patTemplate Tags and attributes for a list of all tags and attributes). When parsing a template, the parser divides the page in several chunks and treats them as separate templates. By using patTemplate's API you can hide, display or repeat a certain template.

A template can contain as many other templates as you like.

Templates can be of these types (defined by using the type="..." attribute):

  • Standard – output of the template will always be the same
  • OddEven – you can assign to subtemplates () to this type: Odd and Even, which will be alternated, when the template is repeated
  • Modulo – is like the Odd Even template except that you may have more than two subtemplates. The Odd Even template type is simply a special case of this type where the modulo attribute equals 2.
  • Condition – you can assign as many subtemplate as you like and you have to assign one variable which will be used to compare it with the specified conditions of the subtemplates. This allows you to define different HTML code for each value your condition variable may have. There are two special conditions you can use: default, which is similar to the default in a switch/case statement and empty which will be displayed, when there is no value assigned to the condition variable.
  • SimpleCondition – A situation that often arises is that an error message has to be displayed if an error occured. Normally you would set the error message if it exists or hide the template using setAttribute() if there is none. By using a template of type SimpleCondition you can assign a list of variables (using the requiredvars) that have to be set if the template has to be displayed. If on of these variables is not set, the template will not be visible.

Template Variables

patTemplate supports variables similar to programming languages. There can be local variables (assigned by the addVar method) and global variables (assigned by the addGlobalVar method).

Global variables can only be scalar variables (strings, integers,...) and local variables can also be arrays. If you assign an array to a variable, the template where you assigned the variable will be repeated.

If a condition template uses the useglobals="yes" attribute global variables will be used if no local variables are set.

Variables have to be written in uppercase and may only contain chars, numbers or the underscore (_). Variables are always enclosed in curly brackets, for example, {FOO}.

Variables will be replaced with their values when parsing a template.

There are several predefined system variables that are available when you set the addsystemvars attribute.

  • PAT_ROW_VAR – you can use this when you want to enumerate a template that is automatically repeated. Just place the variable PAT_ROW_VAR in your template, where you'd like to enumeration to appear (can also be used for javascript mouseovers).
  • PAT_IS_ODD –

Tag Attributes

Templates can have different attributes, the can be set using setAttribute or by placing the attributes in the Tags.

See patTemplate Tags and attributes for details.


The downloadable package of patTemplate contains several examples (currently only in German), which explain the basic functions.

Last Updated ( Thursday, 30 December 2004 )
< Prev