Difference between revisions of "Help:Template"

From ArchWiki
Jump to: navigation, search
(Usage: caps, rm useless colons)
(Escape template-breaking characters: rewrite, improve clarity)
Line 44: Line 44:
 
===Escape template-breaking characters===
 
===Escape template-breaking characters===
  
There are some characters that, if used inside a template, will break its output: most frequently this happens with {{ic|1==}} (the equal sign) and {{ic|<nowiki>|</nowiki>}} (the pipe sign).
+
There are some characters that, if used inside a template, will break its output: most frequently this happens with "=" (the equal sign) and "|" (the pipe sign).
  
 
The easiest and most effective solutions to this problem are:
 
The easiest and most effective solutions to this problem are:
  
* Using numbered parameters like in:
+
==== Named parameters ====
{{Note|1=This method is effective only with = and is very useful with query strings in URLs, e.g. https://www.archlinux.org/?foo=bar}}
+
Explicitly introduce template parameters with their names or positional numbers. This is effective only with "=" and is very useful with query strings in URLs or variable definitions. For example:
{{bc|<nowiki>{{Note|1=This method is effective only with = and is very useful with query strings in URLs, e.g. https://www.archlinux.org/?foo=bar}}</nowiki>}}
+
  
* Replacing the offending characters with their respective HTML entities, like in:
+
{{bc|<nowiki>{{Tip|1=https://www.archlinux.org/?foo=bar}}</nowiki>}}
{{Note|This method supports all kinds of characters, including &#61;, &#124; and &#125;&#125; ( https://www.archlinux.org/?foo&#61;bar )}}
+
{{bc|<nowiki>{{Note|This method supports all kinds of characters, including &amp;#61;, &amp;#124; and &amp;#125;&amp;#125; ( https://www.archlinux.org/?foo&amp;#61;bar )}}</nowiki>}}
+
  
* Enclosing the offending characters in <nowiki><nowiki></nowiki> tags, like in:
+
{{Tip|1=https://www.archlinux.org/?foo=bar}}
{{Note|<nowiki>This method displays all kinds of characters ( = | }} ), but completely prevents the wiki engine from processing text markup, like links ( https://www.archlinux.org/ ) and other templates ( {{ic|foo}} ).</nowiki>}}
+
 
{{bc|<nowiki>{{Note|<nowiki>This method displays all kinds of characters ( = | }} ), but completely prevents the wiki engine from processing text markup, like links ( https://www.archlinux.org/ ) and other templates ( {{ic|foo}} ).&lt;/nowiki>}}</nowiki>}}
+
Or, with multiple parameters:
 +
 
 +
{{bc|<nowiki>{{hc|1=$ echo "="|2="="}}</nowiki>}}
 +
 
 +
{{bc|<nowiki>{{hc|head=$ echo "="|output="="}}</nowiki>}}
 +
 
 +
{{hc|1=$ echo "="|2="="}}
 +
 
 +
==== HTML entities ====
 +
Replace the offending characters with their respective HTML entities. This method supports all kinds of characters, including "=", "|" and "}}". For example:
 +
 
 +
{{bc|<nowiki>{{Tip|&amp;#61; &amp;#124; &amp;#125;&amp;#125;}}</nowiki>}}
 +
 
 +
{{Tip|&#61; &#124; &#125;&#125;}}
 +
 
 +
==== nowiki tags ====
 +
Enclose the offending characters in {{ic|<nowiki><nowiki></nowiki>}} tags. This method displays all kinds of characters, but completely prevents the wiki engine from processing text markup, like links and other templates. For example:
 +
 
 +
{{bc|<nowiki>{{Tip|&lt;nowiki>= | }} https://www.archlinux.org/ {{ic|foo}}&lt;/nowiki>}}</nowiki>}}
 +
 
 +
{{Tip|<nowiki>= | }} https://www.archlinux.org/ {{ic|foo}}</nowiki>}}
  
 
==Creation==
 
==Creation==

Revision as of 04:41, 7 December 2013

A template is a piece of predefined wikitext that can be inserted into an article. Templates are primarily used to aid in formatting content.

Usage

Templates are used by adding the following markup to an article:

{{Template Name}}

Most templates take additional arguments, such as Template:Note:

{{Note|This text should be noted.}}

which produces:

Note: This text should be noted.

Some templates use named parameters, such as Template:hc:

{{hc|head=/etc/rc.local|output=exit 0}}

which produces:

/etc/rc.local
exit 0

The general format is:

{{Template Name|param1|param2|...|paramN}}

See each template's page for specific usage instructions.

Style

  • Templates should be used with the capitalization shown in the examples in their pages, for example {{Pkg|... and {{ic|... are correct, while {{pkg|... and {{Ic|... are not.
  • There should be no spaces around the template name: {{Template Name|... is correct, while for example {{ Template Name |... is not.

Escape template-breaking characters

There are some characters that, if used inside a template, will break its output: most frequently this happens with "=" (the equal sign) and "|" (the pipe sign).

The easiest and most effective solutions to this problem are:

Named parameters

Explicitly introduce template parameters with their names or positional numbers. This is effective only with "=" and is very useful with query strings in URLs or variable definitions. For example:

{{Tip|1=https://www.archlinux.org/?foo=bar}}

Or, with multiple parameters:

{{hc|1=$ echo "="|2="="}}
{{hc|head=$ echo "="|output="="}}
$ echo "="
"="

HTML entities

Replace the offending characters with their respective HTML entities. This method supports all kinds of characters, including "=", "|" and "}}". For example:

{{Tip|&#61; &#124; &#125;&#125;}}
Tip: = | }}

nowiki tags

Enclose the offending characters in <nowiki> tags. This method displays all kinds of characters, but completely prevents the wiki engine from processing text markup, like links and other templates. For example:

{{Tip|<nowiki>= | }} https://www.archlinux.org/ {{ic|foo}}</nowiki>}}
Tip: = | }} https://www.archlinux.org/ {{ic|foo}}

Creation

Note:
  • Only create relevant templates. If you are attempting to create a very specialized template that will likely only ever be used on a few articles, please do not bother, avoid cluttering up the templates namespace.
  • Only create concise templates. Remember The Arch Way: Keep It Simple, Stupid!

The following template should be used when creating new templates to facilitate usage and editing:

<noinclude>{{Template}}

'''A brief description of the template'''

====Usage====

{{ic|<nowiki>{{Template Name|param1|param2|...|paramN}}</nowiki>}}

====Example====

{{Template Name|param1|param2|...|paramN}}</noinclude><includeonly>Template code goes here...</includeonly>

To begin the creation process, simply visit Template:Template Name (substituting Template Name with the desired name of the template), edit, and add the relevant wikitext.

List of templates

The templates that users can use directly in articles on the ArchWiki are listed below. Click on the links to see their detailed usage. For a list that also includes localizations and meta templates see Special:AllPages/Template:, Special:PrefixIndex/Template: or Special:MostLinkedTemplates.

Warning: Please do not experiment with existing templates. If you want to edit a non-protected template, copy the text to Template:Sandbox, edit and test it there, and copy it back when it works. It is strongly recommended (and necessary for protected templates) to suggest any modifications on discussion pages first.

Testing

Article status templates

Related articles templates

Code formatting templates

Note templates

Miscellaneous templates

Package templates

See also