Logic Test

You can apply some if-else logic (there are also other logic tests like defined, empty, not-empty).
Note the if-else test switch the context if the evaluated property is an object (if typeof data[property] == 'object')

Filtering Data

You can alter data before there are applied to the template using filters. filters can be used with any predefined tag (or custom tags).
You can apply multiple filters at once, they must be separated by one or more spaces. you can't supply parameters to filters.

Rendering Data With Modifiers

You can alter data before they are rendered using modifiers. You can pass parameters to modifiers by simply adding them after the modifier name, they must be separated by one or more spaces.
there are two predefined modifiers:

Modifier escape

Escape HTML special chars whether escape string is enabled by default or not.

Syntax:

var tmpl = "my name is {escape name}", // escape &, < and >, " and '

Modifier raw

Return string as is whether escape string is enabled by default of not.

Template Tag If

Tests if the given property exists and is not a falsy value. the context may be switched if the property is evaluated to an object.

Syntax:

{if:property} match1 [{else:property} match2]{/if:property}

Rules

if the property does not exists or is evaluated to a falsy value (undefined, null, false, an empty string, an empty array or zero) then match2 is used in the current context.

if the property exists in the currrent context then match1 is used. if the property is evaluated to an object, the replacement context of match1 is switched to that object, else match1 will be used in the current context.

Template Tag Defined

tests if the given property exists and is not null or undefined. the context is not switched.

Syntax:

{defined:property} match1 [{else:property} match2]{/defined:property}

Rules

if the property exists and is not undefined or null then match1 is used in the current context, else match2 is used in the current context

Syntax: {if:property} match1 [{else:property} match2]{/if:property}

Template Tag Not Empty

tests if the given property exists and is not a falsy value (undefined, null, false, an empty string, an empty array or zero). the context is not switched

Syntax:

Rules

if the property exists and is evaluated to a not a falsy value then match1 is used in the current context, else match2 is used in the current context

Template Tag Empty

tests if the given property does not exists or is a falsy value (undefined, null, false, an empty string, an empty array or zero).

Syntax:

{empty:property} match1 [{else:property} match2]{/empty:property}

Rules

if the property does not exists or is evaluated to a falsy value then match1 is used in the current context, else match2 is used in the current context

Template Tag Repeat

Iterates over the given property

Syntax:

{repeat:property} match1{/repeat:property}

Rules

if the property is evaluated to a an array then every elements will be susbstituted to match1. if the result of the evaluation is an object and that object contains a property 'each' which is a function, this property will be used to iterate over the object properties. if match1 contains '{.}' then '{.}' will be replaced by the current property value.

Template Tag Loop

this tag works exactly like the repeat tag, but iteration is done over the current context.

Syntax: {loop:} match1{/loop:}

Template Method Substitute

substitute the given object into the given string template.

Syntax:

Returns:

(string)

Arguments:

string - (string) input template

data - (object) global context

Template Method Compile

compile the given template to a function for optimal performances. after a call to setOptions, addFilter or addModifier, the previously returned result becomes obsolete.
the function return a string. the function accept a second optional parameter. if this parameter is set to true, the function will return an array of Elements.

Template Method Setoptions

Syntax:

Template Method Addfilter

allow you to alter the data actually replaced in a given tag. this function accepts either a property name/function or an object with properties names as keys and functions as values.
you can apply multiple filter to a tag, they must be separed by one or many spaces.

Modifier function Arguments:

context - (mixed) replacement context

property - (string) property name.

Known Issues

The template should not contain identical nested tag/property tokens because this will lead to unpredictable result. this is because the first token will always match the nearest closing match.
this template for example is not valid: '{repeat:name} {repeat:names}{whatevergoeshere} {/repeat:names} {/repeat:names}'

Discuss

A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.