This is the documentation of the Template/Programming Language of the Stupid Template Engine, or STE T/PL
The STE T/PL consists of four basic elements:
Everything that is not a Variable, a Tag or a Pseudotag is Text.
Also everything that is wrapped in the ste:rawtext pseudotag will be Text, whereby all Tags and Variables will not be parsed.
Will result in one text-element, but
Foo
will result in one text-element and one tag-element containing one variable-element.
$baz[herpdederp]]]>
Variables start with a $
or can be wrapped within ${
and }
, so vou can write this: ${foo}ish
Variable have names, these names can consist of letters (english alphabet; upper and lower case), numbers and underscores (_
). As a regex: [a-zA-Z0-9_]+
A variable can also be an array. To access an array, wrap the desired fieldname within [
and ]
. A fieldname can be constructed of Text and othe Variables. So you can dynamically access fields: $foo[$bar]
. These fieldnames can also be nested or concatenated: $foo[$bar[baz]][herp][$de[derp]]
If you want a literal $
char, you can escape it: \$
Variables in STE T/PL are typeless, everything ist text. In a boolean context, empty text usually represents false, else true.
A Tag can be compared to a function. A Tag can have parameters and children elements.
A Tag looks like a XML-Tag with the ste-Namespace.
Just like their XML counterparts, they can wrap other elements (bar
) or can be self-closing (]]>
).
And they can have additional parameters (or "attributes", using the XML terminology): ]]>
A Tag is wrapped in <
and >
. The tag's name always start with ste:
and can then consist of letters, numbers and underscores (Regex: [a-zA-Z0-9_]+
).
If the tag is self-closing, the last char is a /
(e.g.: ]]>
).
If the tag is a closing one, the first char is a /
. An opening Tag does not have a /
.An example of an opening-closing Tag pair wrapping the text bar
: bar]]>
Parameters of a tag consists of a name and the corresponding value (wrapped in "
or '
) seperated by an =
.
Parameters are seperated by any whitespace (space, tab or newline) char.
Parameter values can consist of Text and Variable elements but not of Tags!
If you need a literal "
or '
in a parameter value, you can escape them: \"
or \'
.
When using variables in paramter values, they will be "replaced" by their value. Because many tags need the variable and not its content, they expect only the variable's name. If you then write foo="$bar"
, the tag will not operate on the bar
variable but on the Variable with the name stored in $bar
! So read the instructions to the tag carefully!
Example: de
Pseudotags look like normal tags, but they perform special tasks. There are currently two pseudotags:
With the ste:comment pseudotag you can comment your template/code. Everything between <ste:comment>
and </ste:comment>
will be ignored, before the real tokenization of the code starts.
The ste:rawtext pseudotag will output a Text element with its wrapped content. It will prevent parsing of the content. Useful if you are embedding another script language, which uses the $
char or also has a XML-Like syntax. No escape sequences will be translated! Can not be used in Tag parameter values!
To get a literal $
, "
or other special chars, STE T/PL gives you the following escape sequences:
Escape Sequence | Result | Can be used in | Notes |
---|---|---|---|
\$ | $ | Text elements | |
\" | " | Tag parameter values | |
\' | ' | Tag parameter values | |
\? | ? | Text elements | More info: short if-clause |
\{ | { | Text elements | More info: short if-clause |
\} | } | Text elements | More info: short if-clause |
\| | | | Text elements | More info: short if-clause |
\\ | \ | Everywhere, where the other escape sequences are valid |
Escape sequences are not translated in Pseudotags
STE has some builtin Tags, that makes programming in STE T/PL possible.
The ste:if Tag provides an if-clause to STE T/PL.
ste:if can have the subtags ste:then and ste:else. Everything between <ste:if>
and </ste:if>
, that is not an ste:then or ste:else tag, will be used as the condition.
Because STE T/PL is typeless, every empty string (trailing whitespaces will be ignored) is considered as false, everything else is true.
If the condition is true (i.e. not empty), the content of the ste:then block will be executed. Otherwise the ste:else tag (if present) will be executed.
The ste:then Tag is mandatory, the ste:else tag is optional.
Example:
If
$foo
$foo
is not empty, then Bar
will be executed, otherwise Baz
.
Because if-clauses are used often, there is an short syntax:
?{condition|then|else}
This is equavilent to:
condition
?
, {
, |
and }
can be escaped
In this variant, the else part is not optional!
WARNING: short if-clauses can not be nested!
With the ste:cmp tag you can compare two values.
ste:cmp is selfclosing, the compared values are passed by parameters.
It compares two values, a and b using an operator.
a and b can be passed in two ways:
var_x
parameter. The parameter value is a variable name.text_x
parameter. The parameter value is a text.x
is either a
or b
).
The operator is passed wth the op
parameter. Following parameters are available:
op value |
Description |
---|---|
eq |
a and b are equal |
neq |
a and b are not equal |
lt |
a is less than b |
lte |
a is less or equal b |
gt |
a is greater than b |
gte |
a is greater or equal b |
If the comparasion was true, a non-empty text will be returned, otherwise an empty text, so you can use ste:cmp with ste:if
Example:
If the variable
foo
has the content bar
, :-)
will be returned, :-(
otherwise.
The ste:not Tag will logically invert its content. If it is an empty text (i.e. false), it will return a non-empty text (i.e. true) and vice versa.
Example:
If the variable
foo
is empty (i.e. false), :-)
will be returned, :-(
otherwise.
If the enclosed text is a number, and the number is even, this tag will return a non-empty text (i.e. true), an empty text (i.e. false) otherwise.
ste:for provides a counter loop.
ste:for has these parameters:
parameter name | Mandatory? | Description |
---|---|---|
start |
Yes | Begin counting at this number. |
stop |
Yes | Stop counting at this number (inclusive). |
step |
No | What amount should be added to the counter at each round? (Default: 1) |
counter |
No | The current number will be stored in this variable (expects a variable name). |
Example:
Will count from 10 down to 0 and output the number followed by an HTML line break.
$i
]]>
ste:foreach will loop through an array.
ste:foreach has these parameters:
parameter name | Mandatory? | Description |
---|---|---|
array |
Yes | The array to be looped through. |
key |
No | The array key will be stored in this variable (expects variable name). |
value |
Yes | The value of the current element will be stored in this variable (expects variable name). |
counter |
No | Expects a variable name. If given, the current number of iterations will be stored in this variable. Starts with 0. |
Example:
This code will loop through the array
Number: $i
Key: $k
Value: $v
]]>foo
and return the counter $i
, the key $k
and the value $v
of the current iteration.
Create an infinitive loop. You can get out of the loop using the ste:break tag. Can be used to emulate othe loop constructs like while loops.
Example:
This code will return
...
while <ste:foo />
returns an empty text (i.e. false).
When this self-closing tag is called, the current loop (ste:for, ste:foreach, ste:infloop) will be aborted.
When this self-closing tag is called, the current loop(ste:for, ste:foreach, ste:infloop) will go to the next iteration, aborting the current iteration.
This self-closing tag loads and executes anoter template. The name
parameter (mandatory) defines the template to load.
Because each template must be parseable and transcompilable by itself, this is not a inclusion of another template. So you can not do this:
slave.tpl:
master.tpl
bla]]>
]]>
But you can do this:
slave.tpl:
master.tpl$bar]]>
ste:block provides an easy way for writing master templates. Every block has a name. When a block is defined twice, the second will overwrite the first one.
The name can be set with the name
parameter.
Example:
master.tpl
slave.tpl:Content:
When executing slave.tpl, master.tpl will be loaded and its
content
block will be replaced with the new one (Much cooler content :-)
) but leave the original sidebar
block.
Blocks can not be nested.
ste:set will set a variable. The parameter var
takes the name of the variable to set. The content of the Tag will be the new content of the variable.
Example:
This will set the variable bar]]>
foo
to bar
.
Tag parameter values can not contain Tags. ste:set can be used to bypass this:
To perform mathematical calculations, you can use ste:math. ste:math calculates the mathematical formula it is wrapped around and returns the result. The formula is in the usual infix-notation [ext. Link] and has these operators: +
, -
, *
, /
and ^
. Numbers are always decimal, the decimal mark is .
and numbers can be prefixed with an -
to indicate a negative number. It is a good idea to wrap a negative number in brackets to prevent wrong evaluation (because -
is also an operator). Calculations can be grouped with brackets: (
and )
.
Real numbers are supported, complex numbers not.
Formulas are evaluated at runtime, not during transcompilation.
Example:
(2+3+4) * (1.5 - (-0.5))]]>
will return 18
.
ste:mktag allows you to define own Tags using STE T/PL.
The parameter name
(mandatory) expects the name of the new tag. If your tag requires some parameters, you can specify them using the optional mandatory
parameter. Names of the mandatory parameters are seperated by |
.
The Variable _tag_parameters
(associative array) will hold all given parameters and their values.
With the ste:tagcontent tag you can execute the tags content.
ste:mktag will be transcompiled like any other code. So your custom tag will be almost as fast as a plugin coded in PHP.
Example:
Will output:
8
6
4
2
0
]]>