Difference between revisions of "Help:Template"

From ArchWiki
Jump to: navigation, search
(update link(s) (avoid redirect), comply with Help:Style#Title)
m (update template name)
Line 147: Line 147:
 
* [[Template:App]]
 
* [[Template:App]]
 
* [[Template:Bug]]
 
* [[Template:Bug]]
* [[Template:Linkrot]]
+
* [[Template:Dead link]]
  
 
===Package templates===
 
===Package templates===

Revision as of 17:42, 26 March 2014

zh-CN:Help:Template

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). Solutions to this problem are described below.

Named parameters

If the problem is only with "=" signs, the recommended solution is to explicitly introduce template parameters with their names or positional numbers. This is very useful with query strings in URLs or variable definitions, but will not work for other offending characters, like "|". For example:

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

Or, with multiple parameters:

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

nowiki tags

If you are having problems with characters other than "=", e.g. "|", the recommended solution is to enclose the whole parameter in <nowiki> tags. This method displays all kinds of characters, but completely prevents the wiki engine from processing text markup, such as links and other templates. For example:

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

Enclosing only specific parts (or even single characters) in <nowiki> tags still works of course, but for readability it is recommended to use such method only if links or other templates have to be normally displayed. For example:

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

HTML entities

Replacing the offending characters with their respective HTML entities always works, but since it reduces the readability of the source text, it is recommended only when the solutions above are not practicable. For example:

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

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
https://wiki.archlinux.org/index.php?title=Help:Template&curid=4272&diff=307154&oldid=302590
wiki.archlinux.org
crawl=CC-MAIN-2017-22
33174
application/http; msgtype=response
sha1:7NO7HOEDGBTB2WMVI6PQM2UEN35HMFT7
<urn:uuid:85dec58d-3d2c-44cb-9df0-39bd751a026f>
2017-05-30T11:59:23Z
5.9.250.164
text/html
sha1:OHCSQ6AFYDGD33SPLWUGLINMLMMYFI2I
<urn:uuid:c76c7fb7-0795-425b-8c60-eea4218cd2e8>
https://wiki.archlinux.org/index.php?title=Help:Template&curid=4272&diff=307154&oldid=302590
length
response
<urn:uuid:48c1bfae-79bf-4cc8-9d51-efbb9b7440df>
robots: classic
hostname: ip-10-185-224-210.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2017-22
operator: Common Crawl Admin
description: Wide crawl of the web for May 2017
publisher: Common Crawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf