Help:Template

From Alpine Linux
Revision as of 10:46, 24 March 2012 by Dubiousjim (talk | contribs) (Cancelled REDIRECT, added content)

This page is more about designing templates than using them. For details of how to use existing templates, see Project:Markup syntax or the documentation for any template.


To include a template---or any page---in another page:

  • {{T}} includes Template:T
  • {{:Page name}} includes Page name
  • {{subst:T}} or {{subst::Page name}} are instead replaced by the current contents of Template:T or Page name
  • {{msgnw:T}} includes [[Template:T] in <nowiki> style


Templates have a limited condition-testing functionality. The following were based on code from the MediaWiki manuals:

  • {{Ifn|value|result}} works like shell's if [ -n "value" ]; then result; fi
  • {{Ifz|value|result}} works like shell's if [ -z "value" ]; then result; fi
  • {{If|value|resultyes|resultno}} works like shell's if [ -n "value"]; then resultyes; else resultno; fi
  • {{Ifeq|value|test|resultyes|resultno}} works like shell's if ["value" = test ]; then resultyes; else resultno; fi

==

{{if|value|then|else}} yields then if value isn't blank; otherwise it yields else. One limitation: {{if|2=then}} yields then (but works properly if value is defined and empty, or else is defined).

{{ifz|value|result}} yields result if value is blank.

{{ifn|value|result}} yields result if value isn't blank. One limitation: {{ifn|2=result}} yields result (but works properly if value is defined and empty).

{{ifeq|value|test|then|else}} yields then if value equals test; otherwise it yields else.

=

Skeleton for a new template:

<noinclude>{{Template}}
Short description.

=== Usage ===
Longer description.

<pre>{{Foo|arg}}</pre>

Further comments.

=== Example ===

<pre>{{Foo|arg}}</pre>

will produce:
{{Foo|arg}}

=== See also ===

* [[:Template:Bar]]

</noinclude><includeonly>EXPANSION</includeonly>


Misc

markup ... {{{1}}} {{{2|default}}} ...


{{T|1=a=alpha|reason=...}}
  {{{1|default}}}
  {{{reason}}}

Explicitly named/numbered args are trimmed, to preserve whitespace have to use implicitly numbered args.
Inside a template, substrings beginning with "*", "#", ":", or ";" are automatically prefixed by a 
newline. Use `a{{{dummy|;}}}b` to generate `a;b`. (`dummy` could be the empty string.)

Use {{ns:0}} for empty string.

Template:Cat uses {{#tag:nowiki|...}} around its {{{2}}}.