A template is a page whose text other pages include. When the template changes, every page using it
is updated. Templates live in the Template: namespace: the template Infobox is the page
Template:Infobox.
Using a template
edit| Form | Use |
|---|---|
::tpl[Infobox]{name="Lazarus" version=4.0} |
on a line of its own |
:tpl[Version]{1=4.0} |
inside a sentence |
:::tpl{name=Example} ... ::: |
with a block of text, passed as the parameter body |
Parameters are written name=value, with quotes when the value contains spaces: title="Two words".
Parameters numbered 1, 2, ... are the unnamed parameters of the old wiki.
A container passes the text between its lines to the template:
:::tpl{name=Example}
program Hello;
:::
A template that does not exist shows as a red link to its page.
Writing a template
editA template is Markdown with placeholders in double braces:
Version **{{version}}** of {{name}}.
| Placeholder | Means |
|---|---|
{{name}} |
the value of the parameter name |
{{#name}} ... {{/name}} |
the text in between, only when name is given |
{{^name}} ... {{/name}} |
the text in between, only when name is missing or empty |
{{PAGENAME}} |
the name of the page that uses the template |
\{\{ |
two braces as text |
Default values go in the settings block of the template:
---
params:
name: World
---
Hello **{{name}}**{{#note}} ({{note}}){{/note}}
Text in a :::noinclude container is shown on the template page only, not in the pages using it.
Use it to document the template:
:::noinclude
Shows a greeting. Parameters: `name` (default World), `note` (optional).
:::
:category[Name] in the template puts every page using it in that category.
Names of the current page
editThese placeholders refer to the page that uses the template. For the page Help:Big book/Part two/de:
| Placeholder | Value |
|---|---|
{{PAGENAME}} |
Big book/Part two/de |
{{FULLPAGENAME}} |
Help:Big book/Part two/de |
{{NAMESPACE}} |
Help |
{{BASEPAGENAME}} |
Big book/Part two |
{{ROOTPAGENAME}} |
Big book |
{{SUBPAGENAME}} |
de |
{{LANGSUFFIX}} |
/de for a translation, empty otherwise |
{{SITENAME}} |
the name of this wiki |
Outside templates, :var[PAGENAME] inserts the same values into a page.
Choices
editPlaceholders have no conditions of their own. For a choice between values, a template declares computed values in its settings block. For example, an icon chosen by the first parameter:
---
computed:
icon:
switch: "{{1}}"
cases:
Linux: ""
macOS:
iOS: ""
default: ""
---
{{icon}} {{1}}
Other operations are if, ifeq, ifexist, lc, uc, lcfirst, ucfirst, urlencode,
titleparts, language, withoutlanguage, localurl and fullurl, as the parser functions of the
old wiki. Templates converted from the old wiki already use them; open one with Edit to see examples.
Errors
editA template that cannot be shown, for instance because it includes itself or a placeholder is not closed, shows as a red error box naming the problem. The rest of the page is shown as usual.