From 7449faaa76a5b4008fd51a6562cca2e0a852ea6b Mon Sep 17 00:00:00 2001
From: Laria Carolin Chabowski This is the documentation of the Template Language of the STE Template Engine. The STE Template Language 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.The STE Template Language
TOC
-
+
Basic Elements
Text
will result in one text-element and one tag-element containing one variable-element.
Foo <ste:bar>$baz[herpdederp]</ste:baz>
Variables start with a $
or can be wrapped within ${
and }
, so you 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 other 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 are typeless, everything is 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.
@@ -124,14 +124,14 @@
When using variables in parameter 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: <ste:foo bar="baz" herp="literal quote sign: \"">de <ste:derp hehe="hoho$wtf[xd]" /></ste:foo>
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 gives you the following escape sequences:
Escape sequences are not translated in Pseudotags
- +STE has some builtin Tags, that makes programming in STE possible.
- +The ste:if Tag provides an if-clause to STE.
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.
<ste:if>condition<ste:then>then</ste:then><ste:else>else</ste:else></ste:if>
?
, {
, |
and }
can be escaped
In this variant, the else part is not optional!
- +With the ste:cmp tag you can compare two values.
ste:cmp is selfclosing, the compared values are passed by parameters.
@@ -285,7 +285,7 @@This is equivalent to:
<ste:cmp text_a="a" op="operator" text_b="b" />
~
, {
, |
and }
can be escaped.
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.
@@ -293,10 +293,10 @@
If the variable <ste:if>
<ste:not>$foo</ste:not>
<ste:then>:-)</ste:then>
<ste:else>:-(</ste:else>
</ste:if>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.
@@ -338,7 +338,7 @@
Will count from 10 down to 0 and output the number followed by an HTML line break.
<ste:for start="10" stop="0" step="-1" counter="i">
$i<br />
</ste:for>
ste:foreach will loop through an array.
@@ -388,7 +388,7 @@
This code will list all array elements or will display <ste:foreach array="foo" value="v">
<p>$v</p>
<ste:else>
Array \$foo is empty.
</ste:else>
</ste:foreach>Array $foo is empty
if the array $foo
is empty.
Creates an infinitive loop. You can get out of the loop using the ste:break tag. Can be used to emulate other loop constructs like while loops.
@@ -396,16 +396,16 @@
This code will return <ste:infloop>
<ste:if>
<ste:foo />
<ste:then><ste:break /></ste:then>
</ste:if>
...
<ste:infloop>...
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 another 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:
+Because each template must be parseable and compilable by itself, this is not a inclusion of another template. So you can not do this:
slave.tpl:
@@ -419,7 +419,7 @@
master.tpl<ste:foo>
bla
<ste:baz>
<ste:load name="slave.tpl" />
</ste:baz>
ste:block provides an easy way for writing master templates. Every block has a name. When a block is defined twice, the second one will overwrite the first one.
The name can be set with the name
parameter.
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.
@@ -444,10 +444,10 @@
Tag parameter values can not contain Tags. ste:set can be used to bypass this:
<ste:set var="temp"><ste:foo /></ste:set>
<ste:bar baz="$temp" />
ste:setlocal is used like ste:set, but only a local variable will be set (ste:set would overwrite a variable, if it was declared in a parent scope). - +
ste:get will return the content of a variable. The parameter var
takes the name of the variable to get. Useful, if you want to get a variable which name is stored in a variable.
@@ -455,30 +455,30 @@
This will get the variable with the name that is stored in the variable <ste:get var="$foo" />
foo
.
To perform mathematical calculations, you can use ste:calc. ste:calc 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.
+Formulas are evaluated at runtime, not during compilation.
Example:
<ste:calc>(2+3+4) * (1.5 - (-0.5))</ste:calc>
will return 18
.
This Tag is pretty slow, because the formula is not transcompiled and only evaluated at runtime. For some simple increment and decrement operations it is better to use the ste:inc and ste:dec Tags from the standard library.
- +This Tag is pretty slow, because the formula is not compiled and only evaluated at runtime. For some simple increment and decrement operations it is better to use the ste:inc and ste:dec Tags from the standard library.
+ste:mktag allows you to define own Tags using the STE Template Language.
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 separated 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.
+ste:mktag will be compiled like any other code. So your custom tag will be almost as fast as a plugin coded in PHP.
Example:
Will output:<ste:mktag name="countdown" mandatory="from|counter">
<ste:for start="$_tag_parameters[from]" stop="0" step="-1" counter="$_tag_parameters[counter]">
<ste:tagcontent />
</ste:for>
</ste:mktag>
<ste:mktag name="double">
<ste:calc><ste:tagcontent /> * 2</ste:calc>
</ste:mktag>
<ste:countdown from="5" counter="i">
<ste:double>$i</ste:double><br />
</ste:countdown>
10<br/>
8<br />
6<br />
4<br />
2<br />
0<br />
The Standard Library contains some useful tags, which are not builtin but still always available.
If the optional parameter lines
is true (i.e. not empty), then additionally line breaks are converted to <br />
.
Returns the length of then content.
- +Returns the number of elements in the array (variable name given by parameter array
).
Increments (i.e. add 1) a variable (variable name given by parameter var
).
Decrements (i.e. subtract 1) a variable (variable name given by parameter var
).
Formats a time using PHPs strftime format [ext. Link]. The format is given in the tag's content. You can specify a time (unix timestamp) using the timestamp
parameter (defaults to the current time).
@@ -513,21 +513,21 @@
Result:
18. Sep. 2011, 16:49:20
Check, if a value is in an array. The tag takes the variable name of the array by parameter array
.The value to test with will be taken from the tags content.
Returns empty text, if the value is not in the array, otherwise a non-empty text.
- +Join parts of an array together. The array's variable name goes to the array
parameter. The tag's content will be used as the glue, i.e. this will be between two elements.
Returns the joined array
- +Split a text and write the parts to an array. The array
parameter takes the variable name of the resulting array, the delim
parameter the text to split by. The tag's content will be the text to split.
Adding an element to an array. The array
parameter takes the variable name of the array. The key
parameter takes the array key to map the value to, if omitted, the value will be appended to the end of the array. The value is the tag's content.
Filter out array elements by multiple criterias.
All the parameters are names of array variables.
-- cgit v1.2.3-70-g09d2