Help:Template

From Alpine Linux
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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


Including

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


If-templates

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

{{Ifn|value|result}}
Yields result if value isn't blank. (Compare shell's if [ -n "value" ]; then result; fi) One limitation: {{ifn|2=result}} yields result (but works properly if value is defined and empty).
{{Ifz|value|result}}
Yields result if value is blank. (Compare shell's if [ -z "value" ]; then result; fi)
{{If|value|resultyes|resultno}}
Yields resultyes if value isn't blank; otherwise it yields resultno. (Compare shell's if [ -n "value"]; then resultyes; else resultno; fi) One limitation: {{if|2=resultyes}} yields resultyes (but works properly if value is defined and empty, or resultno is defined).
{{Ifeq|value|test|resultyes|resultno}}
Yields resultyes if value equals test; otherwise it yields resultno. (Compare shell's if ["value" = test ]; then resultyes; else resultno; fi)

Now that we've upgraded to MediaWiki >= 1.19.1, though (currently at 1.21.1), we should be able to use {{#if:value|result|resultno}} and {{#ifeq:value|test|resultyes|resultno}}, which don't suffer the above limitations. Here are more details. When I try these, though, I find that they still don't work. Maybe these parser function hooks would need to be explicitly enabled.

Template arguments

In the template's expansion markup, {{{1}}} will expand to the first (implicitly named) argument, and {{{2|default}}} will expand to the second but default to default if the second argument is not supplied. Note that if the template is invoked as {{Foo|arg1|}}, then the second argument has been supplied; here it's the empty string.

Arguments can also be explicitly named/numbered, as when you invoke {{Foo|bar=arg1|2=}}. Arguments supplied in these ways have leading and trailing whitespace trimmed. (Whitespace is preserved when arguments are only implicitly named.)

To suppress expansion of an argument's contents, wrap {{{argument}}} with {{#tag:nowiki|...}}; see Template:Cat for an example.

Inside a template's expansion markup, substrings beginning with *, #, :, or ; are automatically prefixed by a newline. Use start{{{dummy|;}}}finish to generate start;finish. (The empty string may be used for dummy.)

{{ns:0}} expands to the empty string.

If your template arguments are unexpectedly expanding as {{{1}}}, then you neglected to supply the argument; or you supplied text that the wiki markup engine is interpreting in a way you didn't expect. You can stop this from happening by surrounding the relevant text with <nowiki> tags. For example, instead of:

{{Cmd|export PS1="(chroot)$PS1"}}

use:

{{Cmd|<nowiki>export PS1="(chroot)$PS1"</nowiki>}}

A shorter alternative is to explicitly name the first argument:

{{Cmd|1=export PS1="(chroot)$PS1}"}}

See also the escape characters for {{Cat}}, which can be used inside any template invocation.

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>