Template Scripts
You can write simple scripts in templates using string substitution macros.
| $() | nothing |
| $(dollar) | dollar sign |
| $(comma) | comma |
| $(lpar) | left paren |
| $(rpar) | right paren |
| $(comment,arg,…) | nothing; arguments are ignored |
| $(and,arg1,arg2,…) | returns the last argument if all arguments are non-empty |
| $(or,arg1,arg2,…) | returns the first non-empty argument |
| $(not,arg) | returns a non-empty string if the argument is empty, and vice-versa |
| $(if,cond,true) | returns ‘true’ if ‘cond’ is non-empty, otherwise the empty string |
| $(if,cond,true,false) | returns ‘true’ if ‘cond’ is non-empty, otherwise ‘false’ |
| $(if,cond1,true1,cond2,true2,cond2,…) | returns ‘true1’ if ‘cond1’ is non-empty, otherwise ‘true2’ if ‘cond2’ is non-empty, etc. |
| $(unless,cond,…) | same as $(if,$(not,cond),…) |
| $(switch,value,test1,result1,test2,result2,…) | returns ‘result1’ if ‘value’ is the same string as ‘test1’, etc. A trailing ‘resultn’ with no ‘testn’ will be returned as the default if there is no match to a test. |
| $(repeat,num,value) | evaluates ‘value’ ‘num’ times |
| $(prop,name) | page property (see below) |
Use $(prop,name) to get page properties, one-to-one semantic relationships, $(prop,title), $(prop,last-modified-by), $(prop,last-modified-date), $(prop,revision-number), $(prop,created-by), and $(prop,created-date).
Most whitespace is significant, but if a line of wiki text is composed entirely of one macro that results in an empty string, we remove that line, so that this remains one list with two items:
$(if,x,* one)$(if,,* two)$(if,y,* three)
Macros can span multiple lines. We trim leading whitespace from macro arguments if that whitespace includes a newline, so that this macro works even though there is whitespace before the first template parameter (which would otherwise cause the condition to be true), and so that it doesn’t generate any newlines (e.g. before “Mr.”):
$(if, {firstName}, {firstName} {lastName}, Mr. {lastName}) Additional macros are defined but not yet implemented: string comparison and manipulation, integer comparison and arithmetic, variables, loops, and custom macros.