User Tools

Site Tools


en:public:developer:template_system:start

This is an old revision of the document!


Template system

This document explains the language syntax of the Arkadia template system. Arkadia’s template language is designed to strike a balance between power and ease. It’s designed to feel comfortable to those used to working with HTML. If you have any exposure to other text-based template languages, such as Smarty or CheetahTemplate, you should feel right at home with ArKadia’s templates

Philosophy

If you have a background in programming, or if you’re used to languages like PHP which mix programming code directly into HTML, you’ll want to bear in mind that the ArKadia template system is not simply PHP embedded into HTML. This is by design: the template system is meant to express presentation, not program logic.

The Arkadia template system provides tags which function similarly to some programming constructs – an if tag for boolean tests, a for tag for looping, etc. – but these are not simply executed as the corresponding PHP code, and the template system will not execute arbitrary PHP expressions. Only the tags, filters and syntax listed below are supported by default (although you can add your own extensions to the template language as needed).

Templates

Template is simply a text file. It can generate any text-based format (HTML, XML, CSV, etc.). A template contains variables, which get replaced with values when the template is evaluated, and tags, which control the logic of the template. Below is a minimal template that illustrates a few basics. Each element will be explained later in this document.:

<#doctype>
<html>
  <head>
    <#meta_title>
    <#meta_description>
  </head>
  <body>
    <#frame name="topframe">
  </body>
</html>

Why use a text-based template instead of an XML-based one (like Zope's TAL)? We wanted ArKadia's template language to be usable for more than just XML/HTML templates. We use it for emails, JavaScript and CSV. You can use the template language for any text-based format.

Variables

Variables look like this: <#variable>. When the template engine encounters a variable, it evaluates that variable and replaces it with the result. Variable names consist of any combination of alphanumeric characters and the underscore (“_”). The dot (”.”) also appears in variable sections, although that has a special meaning, as indicated below. Importantly, you cannot have spaces or punctuation characters in variable names.

Use a dot (.) to access attributes of a variable. <#section.title> will be replaced with the title attribute of the section object. If you use a variable that doesn't exist, the template system will insert '' (the empty string) by default.

Filters

You can modify variables for display by using filters. Filters look like this: <#name lowercase=“1”> This displays the value of the <#name> variable after being filtered through the lower filter, which converts text to lowercase. To give you a taste of what's available, here are some of the more commonly used template filters:

default

If a variable is false or empty, use given default. Otherwise, use the value of the variable For example:

<#value default="nothing">

lowercase

uppercase

xmlencode

htmlencode

httpencode

JavascriptEncode

rtfencode

en/public/developer/template_system/start.1353394779.txt.gz · Last modified: 2012/11/20 10:59 by admin