Blame for Wiki Templates. View history.
Templates allow you to easy include the full content of a “template” page into another page.
To create a template, simply create a wiki page whose name starts with “Template”, e.g. “Template Greeting”.
? Title Template Greeting Hello! How are you?
To use a template, include this wiki syntax, which will be replaced with the content of the template page:
{{{= Greeting}}}
You can use a template in the middle of a line if you use two brackets instead of three, but not all wiki formatting is supported.
Our greeting: {{= Greeting}}
You can supply parameters when invoking a template.
{{{= Greeting|name=Alice}}}
To use the parameter in the template, surround the parameter name in brackets:
? Title Template Greeting
Hello, {name}!
How are you?
Basically, a segment, like {{= X }}, or a section, like {{{= X }}}, is replaced by the content of the wiki page with the “Template X” (X is the same in the segment, section, and template name). For an example, see Template Example, which uses Template Sandbox. Those examples also demonstrate the use of parameters (e.g. “name” and “excited”) and macros (e.g. $(if)).
This is a template, {name}.
It has two paragraphs$(if,$(switch,{excited},y,y),!,.)
{{{=
Sandbox|name=Sarah|excited=y
}}}
Templates can also be used inline: “{{= Sandbox|name=Ed}}” Yay!
Templates can also be used inline: “” Yay!
You can write simple scripts in templates using string substitution macros.
| $(dollar)() | nothing |
| $(dollar)(dollar) | dollar sign |
| $(dollar)(comma) | comma |
| $(dollar)(lpar) | left paren |
| $(dollar)(rpar) | right paren |
| $(dollar)(comment,arg,…) | nothing; arguments are ignored |
| $(dollar)(and,arg1,arg2,…) | returns the last argument if all arguments are non-empty |
| $(dollar)(or,arg1,arg2,…) | returns the first non-empty argument |
| $(dollar)(not,arg) | returns a non-empty string if the argument is empty, and vice-versa |
| $(dollar)(if,cond,true) | returns ‘true’ if ‘cond’ is non-empty, otherwise the empty string |
| $(dollar)(if,cond,true,false) | returns ‘true’ if ‘cond’ is non-empty, otherwise ‘false’ |
| $(dollar)(if,cond1,true1,cond2,true2,cond2,…) | returns ‘true1’ if ‘cond1’ is non-empty, otherwise ‘true2’ if ‘cond2’ is non-empty, etc. |
| $(dollar)(unless,cond,…) | same as $(dollar)(if,$(dollar)(not,cond),…) |
| $(dollar)(switch,value,test1,result1,test2,result2,…) | returns ‘result1’ if ‘value’ is the same string as ‘test1’, etc. |
| $(dollar)(repeat,num,value) | evaluates ‘value’ ‘num’ times |
| $(dollar)(prop,name) | page property (see below) |
Use $(dollar)(prop,name) to get page properties, one-to-one semantic relationships, $(dollar)(prop,title), $(dollar)(prop,last-modified-by), $(dollar)(prop,last-modified-date), $(dollar)(prop,revision-number), $(dollar)(prop,created-by), and $(dollar)(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:
$(dollar)(if,x,* one) $(dollar)(if,,* two) $(dollar)(if,y,* three)
$(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.”):
$(dollar)(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.
Welcome, Guest! (sign in)