There are many situations when you want to conditionally include some text or another template.
StringTemplate provides simple IF-statements to let you specify conditional includes. For example, in a dynamic web page you usually want a slightly different look depending on whether or not the viewer is "logged in" or not. Without a conditional include, you would need two templates:
page_logged_out. You can use a single
page definition with
) attribute actions instead:
top_gutter_logged_in is located in the
gutter subdirectory of my
IF actions test the presence or absence of an attribute unless the object is a
bool, in which case it tests the attribute for
false. The only operator allowed is "not" and means either "not present" or "not true". For example, "
You can also use
elseif to make a chain of tests:
The first true expression "wins".
Whitespace in conditionals issue
There is a simple, but not perfect rule: kill a single newline after
<endif> (but for
<endif> only if it's on a line by itself) . Kill newlines before
>>. For example,
is identical to:
It is very difficult to get the newline rule to work "properly" because sometimes you want newlines and sometimes you don't. I
decided to chew up as many as is reasonable and then let you explicitly say
<\n> when you need to.