The first and most basic feature of the language is variable substitution. STL uses a syntax that resembles the one implemented by the class string.Template1 from the Python Standard Library):
${expression} defines a substitution placeholder. The expression will be evaluated and the result value will be inserted.
This technique can be used in text nodes and attribute values. For example:
<a href="edit_task?id=${task/id}">${task/title}</a>
The expressions of STL are very simple, its syntax is:
name[/name]*
That is, a sequence of names separated by slashes. The expressions are evaluated this way:
Look the first name in the namespace stack.
If there are more names left, the last value found must be a namespace, then look the next name in that namespace.
Iterate until the last name is consumed.
Once the end of the sequence is reached, we will have a value. If the value is callable, then call it to get the final value.
If the value we get at the end is None, the placeholder will be removed. If the placeholder is alone within an attribute, the attribute will be removed altogether.
If the value is other than None, it will probably be a string, which will be just inserted in the placeholder. If it is something else like an integer, the value will be coerced to a string and inserted into the placeholder.
There is an special case however, the boolean expressions.
Boolean expressions are meant to be used in boolean attributes, for example in HTML we have the attributes checked, disabled, read-only and selected (among others).
Boolean expressions are slightly different than normal expressions:
[not] name[/name]*
They are evaluated the same way than normal expressions, but the value must be a boolean (if it is not it will be coerced to a boolean). If the keyword not is present then we will apply the logical not operator to the value.
Here there is an example:
<input type="checkbox" name="high_priority" value="1"
checked="${task/is_high_priority}" />
If at the end the value is True then STL will insert the name of the attribute into placeholder, as it is the behaviour defined by (X)HTML2. If the value is False the attribute will be removed.
Footnotes