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.

Basic Syntax

All Arkadia template tags are started within <# and closed within >. Most of tags doesn't have closing tag.

Example:

  <#current_language>

Also some template tags has parameters. Parameters added to tags on the same way like in HTML.

Example:

  <#frame name="rightframe">

AnalyzeTagParams

AnalyzeTagParams is a parameter can be added to any arkadia template tag to process sub arkadia template tags in this tag. Value can be 1 and 0 (0 by default not process).

example:

  <#if condition='<#current_url> = /usa/' AnalyzeTagParams="1">
    <span><#current_url></span>
  <#endif>

Statements Syntax

The statement syntax is easy.

If statement

if statement started within <#if> has one parameter condition and ended within <#endif>.

There are two additional tags to represent else and else if statements, <#else> and <#elseif>.

<#elseif> also has one parameter condition.

The result of condition value must be Boolean.

Example:

<#if condintion="a > b">
  <span>A is more than B</span>
<#elseif condition="a < c">
  <span>A is less than C</span>
<#else>
  <span>A is less than B but more than C</span>
<#endif>

Caseof statement

The <#caseof> statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to.

<#caseof expression="<#random range='5'>"
         statement_0="<span>0</span>"
         statement_1="<span>1</span>"                        
         statement_2="<span>2</span>"                                                
         statement_3="<span>3</span>"                                                
         statement_4="<span>4</span>"                                                
         AnalyzeTagParams="1">

<#casecurrentlanguage>

It is a quick variant of <#caseof> statement based on current language of page.

Example:

  <#casecurrentlanguage FRA="I'm on French version of site" 
                        RUS="I'm on Russian version of site" 
                        default="I'm on English version of site">
en/public/developer/template_system/start.1353240744.txt.gz · Last modified: 2012/11/18 16:12 by admin