Help:Template: Difference between revisions
(Redirecting to Alpine Linux Wiki templates) |
Dubiousjim (talk | contribs) (Cancelled REDIRECT, added content) |
||
Line 1: | Line 1: | ||
# | 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 [[Special:AllPages/Template:|any template]]. | ||
To include a template---or any page---in another page: | |||
* <code>{{lb}}T{{rb}}</code> includes [[Template:T]] | |||
* <code>{{lb}}:Page name{{rb}}</code> includes [[Page name]] | |||
* <code>{{lb}}subst:T{{rb}}</code> or <code>{{lb}}subst::Page name{{rb}}</code> are instead replaced by the current contents of [[Template:T]] or [[Page name]] | |||
* <code>{{lb}}msgnw:T{{rb}}</code> includes [[Template:T] in <code><nowiki></code> style | |||
Templates have a limited condition-testing functionality. The following were based on code from the MediaWiki manuals: | |||
* {{lb}}Ifn|value|result{{rb}} works like shell's <code>if [ -n "value" ]; then result; fi</code> | |||
* {{lb}}Ifz|value|result{{rb}} works like shell's <code>if [ -z "value" ]; then result; fi</code> | |||
* {{lb}}If|value|resultyes|resultno{{rb}} works like shell's <code>if [ -n "value"]; then resultyes; else resultno; fi</code> | |||
* {{lb}}Ifeq|value|test|resultyes|resultno{{rb}} works like shell's <code>if ["value" = test ]; then resultyes; else resultno; fi</code> | |||
====== | |||
<nowiki>{{</nowiki>if|<var>value</var>|<var>then</var>|<var>else</var>}} yields <var>then</var> if <var>value</var> isn't blank; otherwise it yields <var>else</var>. | |||
One limitation: <nowiki>{{</nowiki>if|2=<var>then</var>}} yields <var>then</var> (but works properly if <var>value</var> is defined and empty, or <var>else</var> is defined). | |||
<nowiki>{{</nowiki>ifz|<var>value</var>|<var>result</var>}} yields <var>result</var> if <var>value</var> is blank. | |||
<nowiki>{{</nowiki>ifn|<var>value</var>|<var>result</var>}} yields <var>result</var> if <var>value</var> isn't blank. | |||
One limitation: <nowiki>{{</nowiki>ifn|2=<var>result</var>}} yields <var>result</var> (but works properly if <var>value</var> is defined and empty). | |||
<nowiki>{{</nowiki>ifeq|<var>value</var>|<var>test</var>|<var>then</var>|<var>else</var>}} yields <var>then</var> if <var>value</var> equals <var>test</var>; otherwise it yields <var>else</var>. | |||
===== | |||
Skeleton for a new template: | |||
<pre><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> | |||
</pre> | |||
=== Misc === | |||
<pre> | |||
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. | |||
</pre> | |||
[[Template:Cat]] uses <nowiki>{{#tag:nowiki|...}}</nowiki> around its <nowiki>{{{2}}}</nowiki>. | |||
[[Category:Wiki]] |
Revision as of 10:46, 24 March 2012
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}}}.