Pomoc:Template

Z PHPEdia.pl
Skocz do: nawigacji, wyszukiwania

Zobacz również:


In MediaWiki, a template is a page which can be inserted into another page via a process called transclusion. This article provides a detailed look at templates in MediaWiki. If the concept of templates is new to you, you may want to look at A quick guide to templates first.

Notatka:

  • Orginalna wersja tej strony znajduje się Meta-Wikipedia pod adresem: [1]; Wszystkie przykłady szablonów działają na niej. Niestety - nie wszystkie zostały już przeniesione również do naszego systemu, wiąc w celu przekonania się, ile tak naprawdę potrafić szablony - zachćcamy odwiedzenie powyówszego adresu.


General

The template namespace is the namespace with prefix "Template:".

A page in this namespace is called a template. The contents of such a page (either fixed or depending on parameters and/or variables) is designed to be useful for insertion in other pages (transclusion, creating a compound document).

The syntax for insertion of the page "Template:name" is {{name}}. This is called a template tag.

This reference in the wikitext causes insertion of the template content when the referring page is rendered. Various equivalent terms are:

  • calling the template
  • referring to the template
  • including the template
  • using the template

If the page "Template:name" does not exist, then {{name}} works as [[Template:name]], a link to a non-existing page, leading to the edit page. Thus, one way of making a template is putting the tag first, and then following the link.

If name starts with a valid namespace prefix, or a colon, then it is not prefixed with "Template:". This way any page can be used as template (a colon at the start refers to the main namespace). In the case of an image or category, it gives the description part. Using a page outside the template namespace as template can be useful for:

A template only works when referred to from a page in the same project. To use it in another project, one has to copy it to there.

As usual the name is case sensitive except (on most projects) for the first letter, and a blank space is equivalent with an underscore.

Recursive inclusion is possible.

A variable in a template is evaluated after insertion in the referring page, i.e. if {{PAGENAME}} occurs in the wikitext of a template, it is rendered as the name of the referring page, not the name of the template.

A list of templates used on a page, all with links, is given on the edit page. Even on a section edit page the whole list is given, i.e. also the templates used in other sections. (Supported in version 1.4 and higher.)

When saving a page without newline at the end, a newline is automatically added. This is relevant if the page is called as a template: if there is no other newline after the template call, a space is produced; if there is another one, a new paragraph.

If the template contains a numbered list, the above also affects whether numbering is restarted:

{{Numbered list demo}}{{Numbered list demo}}
{{Numbered list demo}}

using Template:Numbered list demo, gives

Szablon:Numbered list demoSzablon:Numbered list demo Szablon:Numbered list demo

Parameters

(supported in versions 1.3 and higher)

Template parameters are either named or numbered. The syntax is {{templatename|parname1=parvalue1|parname2=parvalue2}} with {{{parname1}}}, {{{parname2}}}, etc. tags in the template, or {{templatename|parvalue1|parvalue2}} with {{{1}}}, {{{2}}}, etc. tags in the template. (Note that parameter tags in the template have three braces rather than two.)

Thus the template mechanism involves two kinds of replacements:

  • template calls (double braced) are replaced by template content
  • parameters (triple braced) are replaced by parameter values

Spaces before or after a parameter value are normally ignored:

"{{t|a}}" (using Template:t) gives "Szablon:T".
"{{t| a}}" gives "Szablon:T".
"{{t|a }}" gives "Szablon:T".

A parameter value can contain a piped link; the "|" in such a link is not taken as parameter separator.

Example: "{{t|[[a|b]]}}" gives "Szablon:T".
Example: "{{t|[[a|b]] }}" gives "Szablon:T".

(As usual the text after the link is made part of the link label. In this case the space has effect.)

On rendering, surplus parameter values (including named parameters that do not occur in the template) are ignored: {{t|a|b}} gives Szablon:T.

If a parameter is left undefined, the name of the parameter, with the braces, will be returned.

Example: "{{t2}}" (using Template:t2) gives Szablon:T2

Thus, the default value in the code {{{parameter number or name}}}, and the rendered text on the page itself will be one and the same. E.g., if a template ab has parameter "langs" then a tag {{ab}} in wikitext with the value of "langs" unspecified, shows {{{langs}}}.

To avoid this one may want to specify the parameter anyway like {{ab|langs=}}, {{ab|langs=-}}, or {{ab|langs='''N.A.'''}}.

If a parameter is left undefined, the triple braced parameter name in the result does not function as a parameter if the page is called as a template from another page; if it should, do not omit the parameter value but specify it in terms of a parameter of the calling page; compare:

On a side note, the rendering of the page Template:t2a1 is confusing, as a result of parsing the code differently from when it is used, i.e. called with a parameter.

{{t2||a}} makes the first parameter equal to the empty string rather than leaving it undefined: it gives Szablon:T2. By treating the second unnamed parameter as a parameter with the name "2", the first unnamed parameter can be left undefined.

Example: {{t2|2=a}} gives Szablon:T2.

When a parameter value contains an equal sign, the parameter name and value must be explicitly stated using the form parname=parvalue.

Example: Template:TTT with {{TTT|a=b|c}} gives <HTML>

<HEAD> <TITLE>Company Name</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1250"> <SCRIPT TYPE="text/javascript"> </SCRIPT> </HEAD><link href="css/styles.css" rel="stylesheet" type="text/css">

<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 ONLOAD="preloadImages();">
<IMG SRC="images/top1.gif" WIDTH=54 HEIGHT=54 ALT="">

<A HREF="#" ONMOUSEOVER="window.status='home'; changeImages('home', 'images/home-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('home', 'images/home.gif'); return true;">

<IMG NAME="home" SRC="images/home.gif" WIDTH=51 HEIGHT=54 BORDER=0 ALT="home"></A>

<A HREF="#" ONMOUSEOVER="window.status='info'; changeImages('info', 'images/info-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('info', 'images/info.gif'); return true;">

<IMG NAME="info" SRC="images/info.gif" WIDTH=45 HEIGHT=54 BORDER=0 ALT="info"></A>

<A HREF="#" ONMOUSEOVER="window.status='contact'; changeImages('contact', 'images/contact-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('contact', 'images/contact.gif'); return true;">

<IMG NAME="contact" SRC="images/contact.gif" WIDTH=60 HEIGHT=54 BORDER=0 ALT="contact"></A>
<IMG SRC="images/top2.gif" WIDTH=28 HEIGHT=54 ALT=""> <IMG SRC="images/main.gif" WIDTH=537 HEIGHT=281 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=54 ALT="">
<IMG SRC="images/title.gif" WIDTH=238 HEIGHT=227 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=227 ALT="">
<IMG SRC="images/top3.gif" WIDTH=54 HEIGHT=32 ALT="">

<A HREF="#" ONMOUSEOVER="window.status='about us'; changeImages('about_us', 'images/about-us-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('about_us', 'images/about-us.gif'); return true;">

<IMG NAME="about_us" SRC="images/about-us.gif" WIDTH=75 HEIGHT=32 BORDER=0 ALT="about us"></A>

<A HREF="#" ONMOUSEOVER="window.status='products'; changeImages('products', 'images/products-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('products', 'images/products.gif'); return true;">

<IMG NAME="products" SRC="images/products.gif" WIDTH=72 HEIGHT=32 BORDER=0 ALT="products"></A>

<A HREF="#" ONMOUSEOVER="window.status='partners'; changeImages('partners', 'images/partners-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('partners', 'images/partners.gif'); return true;">

<IMG NAME="partners" SRC="images/partners.gif" WIDTH=72 HEIGHT=32 BORDER=0 ALT="partners"></A>

<A HREF="#" ONMOUSEOVER="window.status='services'; changeImages('services', 'images/services-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('services', 'images/services.gif'); return true;">

<IMG NAME="services" SRC="images/services.gif" WIDTH=68 HEIGHT=32 BORDER=0 ALT="services"></A>

<A HREF="#" ONMOUSEOVER="window.status='news'; changeImages('news', 'images/news-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('news', 'images/news.gif'); return true;">

<IMG NAME="news" SRC="images/news.gif" WIDTH=63 HEIGHT=32 BORDER=0 ALT="news"></A>
<IMG SRC="images/top4.gif" WIDTH=371 HEIGHT=32 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=32 ALT="">
<IMG SRC="images/news1.gif" WIDTH=54 HEIGHT=311 ALT=""> <IMG SRC="images/news2.gif" WIDTH=174 HEIGHT=42 ALT=""> <IMG SRC="images/wel1.gif" WIDTH=329 HEIGHT=62 ALT=""> <IMG SRC="images/wel3.gif" WIDTH=218 HEIGHT=133 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=42 ALT="">

20/04/2004

Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, consetetur <a href="#" class="a">read more</a>
<IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=20 ALT="">
<IMG SRC="images/wel2.gif" WIDTH=25 HEIGHT=71 ALT="">

Lorem ipsum dolor sit amet, consetetur sadi pscing sed diam

Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, consetetur sadi pscing elitr, sed dam <a href="#" class="b">read more</a>
<IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=55 ALT="">

17/04/2004

Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, consetetur <a href="#" class="a">read more</a>
<IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=16 ALT="">
<IMG SRC="images/part1.gif" WIDTH=251 HEIGHT=36 ALT=""> <IMG SRC="images/prod1.gif" WIDTH=153 HEIGHT=36 ALT=""> <IMG SRC="images/prod3.gif" WIDTH=143 HEIGHT=178 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=36 ALT="">
<IMG SRC="images/part2.gif" WIDTH=25 HEIGHT=56 ALT=""> Lorem ipsum dolor sit amet, consetetur sadi pscing sed diam Erat, sed diam voluptua. At rebum. Lorem ipsum dolor sit amet, consetetur sadi pscing elitr, sed dam <a href="#" class="c">read more</a> <IMG SRC="images/prod2.gif" WIDTH=21 HEIGHT=142 ALT=""> Lorem ipsum dolor sit amet, consetetur sadi pscing sed diam Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, consetetur sadi pscing elitr, sed dam <a href="#" class="c">read more</a> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=23 ALT="">

16/04/2004
Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum <a href="#" class="a">read more</a>

Need website hosting? We recommend <a href="http://www.lunarpages.com/?id=webdotcom&campaign=mtt" class="a" target="_blank">LunarPages</a>

<IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=33 ALT="">
<IMG SRC="images/part3.gif" WIDTH=251 HEIGHT=86 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=86 ALT="">
<IMG SRC="images/down.gif" WIDTH=775 HEIGHT=24 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=24 ALT="">

Copyright ???  Your Company Name

Designed by <a href="http://www.mastertemplates.com" target="_blank">MasterTemplates</a>
<a href="#">Home</a> | <a href="#">About Us</a> | <a href="#">Partners</a> | <a href="#">Products</a> | <a href="#">Services</a> | <a href="#">News</a> | <a href="#">Contact Us</a> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=32 ALT="">
<IMG SRC="images/spacer.gif" WIDTH=54 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=51 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=24 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=21 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=51 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=9 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=18 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=10 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=15 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=20 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=28 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=40 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=63 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=75 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=21 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=57 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=75 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=143 HEIGHT=1 ALT="">
</BODY>

</HTML> (non-existing parameter a is assigned the value b), while {{TTT|1=a=b|2=c}} gives <HTML> <HEAD> <TITLE>Company Name</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1250"> <SCRIPT TYPE="text/javascript"> </SCRIPT> </HEAD><link href="css/styles.css" rel="stylesheet" type="text/css">

<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 ONLOAD="preloadImages();">
<IMG SRC="images/top1.gif" WIDTH=54 HEIGHT=54 ALT="">

<A HREF="#" ONMOUSEOVER="window.status='home'; changeImages('home', 'images/home-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('home', 'images/home.gif'); return true;">

<IMG NAME="home" SRC="images/home.gif" WIDTH=51 HEIGHT=54 BORDER=0 ALT="home"></A>

<A HREF="#" ONMOUSEOVER="window.status='info'; changeImages('info', 'images/info-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('info', 'images/info.gif'); return true;">

<IMG NAME="info" SRC="images/info.gif" WIDTH=45 HEIGHT=54 BORDER=0 ALT="info"></A>

<A HREF="#" ONMOUSEOVER="window.status='contact'; changeImages('contact', 'images/contact-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('contact', 'images/contact.gif'); return true;">

<IMG NAME="contact" SRC="images/contact.gif" WIDTH=60 HEIGHT=54 BORDER=0 ALT="contact"></A>
<IMG SRC="images/top2.gif" WIDTH=28 HEIGHT=54 ALT=""> <IMG SRC="images/main.gif" WIDTH=537 HEIGHT=281 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=54 ALT="">
<IMG SRC="images/title.gif" WIDTH=238 HEIGHT=227 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=227 ALT="">
<IMG SRC="images/top3.gif" WIDTH=54 HEIGHT=32 ALT="">

<A HREF="#" ONMOUSEOVER="window.status='about us'; changeImages('about_us', 'images/about-us-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('about_us', 'images/about-us.gif'); return true;">

<IMG NAME="about_us" SRC="images/about-us.gif" WIDTH=75 HEIGHT=32 BORDER=0 ALT="about us"></A>

<A HREF="#" ONMOUSEOVER="window.status='products'; changeImages('products', 'images/products-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('products', 'images/products.gif'); return true;">

<IMG NAME="products" SRC="images/products.gif" WIDTH=72 HEIGHT=32 BORDER=0 ALT="products"></A>

<A HREF="#" ONMOUSEOVER="window.status='partners'; changeImages('partners', 'images/partners-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('partners', 'images/partners.gif'); return true;">

<IMG NAME="partners" SRC="images/partners.gif" WIDTH=72 HEIGHT=32 BORDER=0 ALT="partners"></A>

<A HREF="#" ONMOUSEOVER="window.status='services'; changeImages('services', 'images/services-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('services', 'images/services.gif'); return true;">

<IMG NAME="services" SRC="images/services.gif" WIDTH=68 HEIGHT=32 BORDER=0 ALT="services"></A>

<A HREF="#" ONMOUSEOVER="window.status='news'; changeImages('news', 'images/news-over.gif'); return true;" ONMOUSEOUT="window.status=; changeImages('news', 'images/news.gif'); return true;">

<IMG NAME="news" SRC="images/news.gif" WIDTH=63 HEIGHT=32 BORDER=0 ALT="news"></A>
<IMG SRC="images/top4.gif" WIDTH=371 HEIGHT=32 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=32 ALT="">
<IMG SRC="images/news1.gif" WIDTH=54 HEIGHT=311 ALT=""> <IMG SRC="images/news2.gif" WIDTH=174 HEIGHT=42 ALT=""> <IMG SRC="images/wel1.gif" WIDTH=329 HEIGHT=62 ALT=""> <IMG SRC="images/wel3.gif" WIDTH=218 HEIGHT=133 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=42 ALT="">

20/04/2004

Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, consetetur <a href="#" class="a">read more</a>
<IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=20 ALT="">
<IMG SRC="images/wel2.gif" WIDTH=25 HEIGHT=71 ALT="">

Lorem ipsum dolor sit amet, consetetur sadi pscing sed diam

Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, consetetur sadi pscing elitr, sed dam <a href="#" class="b">read more</a>
<IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=55 ALT="">

17/04/2004

Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, consetetur <a href="#" class="a">read more</a>
<IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=16 ALT="">
<IMG SRC="images/part1.gif" WIDTH=251 HEIGHT=36 ALT=""> <IMG SRC="images/prod1.gif" WIDTH=153 HEIGHT=36 ALT=""> <IMG SRC="images/prod3.gif" WIDTH=143 HEIGHT=178 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=36 ALT="">
<IMG SRC="images/part2.gif" WIDTH=25 HEIGHT=56 ALT=""> Lorem ipsum dolor sit amet, consetetur sadi pscing sed diam Erat, sed diam voluptua. At rebum. Lorem ipsum dolor sit amet, consetetur sadi pscing elitr, sed dam <a href="#" class="c">read more</a> <IMG SRC="images/prod2.gif" WIDTH=21 HEIGHT=142 ALT=""> Lorem ipsum dolor sit amet, consetetur sadi pscing sed diam Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, consetetur sadi pscing elitr, sed dam <a href="#" class="c">read more</a> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=23 ALT="">

16/04/2004
Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum <a href="#" class="a">read more</a>

Need website hosting? We recommend <a href="http://www.lunarpages.com/?id=webdotcom&campaign=mtt" class="a" target="_blank">LunarPages</a>

<IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=33 ALT="">
<IMG SRC="images/part3.gif" WIDTH=251 HEIGHT=86 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=86 ALT="">
<IMG SRC="images/down.gif" WIDTH=775 HEIGHT=24 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=24 ALT="">

Copyright ???  Your Company Name

Designed by <a href="http://www.mastertemplates.com" target="_blank">MasterTemplates</a>
<a href="#">Home</a> | <a href="#">About Us</a> | <a href="#">Partners</a> | <a href="#">Products</a> | <a href="#">Services</a> | <a href="#">News</a> | <a href="#">Contact Us</a> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=32 ALT="">
<IMG SRC="images/spacer.gif" WIDTH=54 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=51 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=24 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=21 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=51 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=9 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=18 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=10 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=15 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=20 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=28 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=40 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=63 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=75 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=21 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=57 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=75 HEIGHT=1 ALT=""> <IMG SRC="images/spacer.gif" WIDTH=143 HEIGHT=1 ALT="">
</BODY>

</HTML> (the first parameter is assigned the value "a=b").

If the parameter is used in a tag like <font size> the default text may give invalid code that is conveniently ignored, rather than resulting in perhaps ugly code being rendered. See e.g. Template talk:Fontsize.

Parameter names are case-sensitive, even with respect to the first letter, even though the template page renders them starting with a capital, and spaces and underscores are not allowed in them.

Note that parameters in the MediaWiki namespace (interface messages) are written differently: as $1, $2, etc., see Meta-Wikimedia:MediaWiki namespace text.

Viewing the contents of a template

To see the contents of a template, one needs to look in the edit box and not just on the page itself, because on the template page:

  • not the variables themselves, but their values are shown; e.g. the page en:Template:Otheruses with the content
: <span class="dablink">''For other uses, see [[{{PAGENAME}} (disambiguation)]].''</span>
shows
For other uses, see Otheruses (disambiguation).

In fact, the rendering on the template page of the wikitext may show more conversions, which can make it confusing and less useful to consider.

msgnw

The prefix msgnw (short for "message, nowiki") is used to display the uninterpreted wikitext of a template (the same thing you'd see if you were editing the page) on another page. An exception is that numbered and unnumbered lists are rendered as such instead of displaying # or * signs. Parameter values are ignored.

Examples:

Template:en

  • {{msgnw:en}} gives [[:Szablon:En]]
  • {{en}} gives Szablon:En

Template:t2

  • {{msgnw:t2|a|b}} gives [[:Szablon:T2]]
  • {{t2|a|b}} gives Szablon:T2

Template:Numbered list demo

{{msgnw:Numbered list demo}} gives: [[:Szablon:Numbered list demo]]

{{Numbered list demo}} gives: Szablon:Numbered list demo

The edit box shows:

#Amsterdam
#Rotterdam
#The Hague

Link for editing a template

The edit link on each page does not allow editing of template text appearing on that page. Therefore it can be desirable to have a special link for that purpose. This link can be put in the template itself. Since these edit links are similar for various templates, it can be made a template itself, with the name of the template as parameter. See e.g. en:template:edit and en:Train.

On Meta there are:

For editing a template ({{{1}}} is the name without prefix):

For editing any file ({{{1}}} is the full page name):

Usage

Templates are useful for any text for which one wants a copy in two or more pages, and there is no need for each copy to be edited independently, to adapt it to the page it is in. Since parameters can be used, versions may to that extent even be different, and parameter values can be edited independently for each.

Templates are not only convenient, but they can also "force" a useful uniformity.

Typical applications are:

Various combinations are possible. E.g., the last two could be combined, so that e.g. every language version of Wikipedia has the same Infobox Countries template (for each project a copy, because the template mechanism can not import across projects), which has parameters for the data, and refers to templates with translations of standard terms.

Navigational templates

A common, simple type of navigational template in a hierarchy of pages is one with the names, with links, of a parent page and child pages. It is placed on all the pages it lists. Thus a page that is not at the top or bottom of the hierarchy has two templates, one with its parent and siblings, and one with its children.

Variations also occur, such as pages having two parents, etc.

Self links do not give any complication: they are neatly displayed in bold and not as link. However, templates should have the correct page names and not rely on redirecting, since the feature does not work in that case.

A navigational template may also just allow going forward and backward in a linear sequence, e.g. en:Template:Pope. For the predecessor of the first and the successor of the last a message like "none" can be used. This is not applicable in the case of a cycle, such as the days of the week.

Composite pages

The wikitext of a page may (partly or fully) consist of tags for the inclusion of other pages (i.e., the "templates" are not necessarily in the template namespace, and are more or less self-contained pages by themselves). Examples are w:en:Wikipedia:Village pump and m:Meta:Translation/Coordination.

This allows the user the choice between viewing the parts separately (e.g. if he has a slow connection) or combinedly. Similar to the section editing feature, it also allows editing a part; however, there is no possibility to have the combined wikitext in the edit box.

Edit history, recent changes, watching pages, and "what links here" work separately for the parts and the composition page, not for the composite page. Related changes works for the parts and for the composite page. Page protection can be set for selected parts and for the composition page, not directly for the composite page.

The talk page of a composition page is used to talk about the composition and the page in general, and could in addition be a composite page of the talk pages of the parts.

A composite page has an integrated TOC and section numbering; the numbering is not reset for each part.

Editing a section of a part can be done directly from the composite page, see editing sections of included templates. After saving, one ends up at the page for the part to which the section belongs.

On projects with the interlanguage link feature the composite page shows the combined interlanguage links of all parts, hence possibly multiple links for one language or even for one page.

Other duplication of content

Duplication of content (whether using a template or not), e.g. putting a section on the relationship of A and B both in the page about A and in that about B, may, depending on the project, not be recommended. It may be confusing and irritating for the reader if the repeated text can not be recognized as such by a special lay-out. It may be better to use links instead, with possible duplication limited to only a short remark about the relationship.

The recommended usages mentioned above do not tend to have these disadvantages.

It is argued that in more cases the nuisances can be mitigated, and that there are substantial benefits in some circumstances. See Help_talk:Template#Duplication of content

Restrictions and possibilities

A pair of double or triple braces inside a pair of double braces

Due to the way in which braces are currently parsed by the software, certain combinations of braces within braces may have non-intuitive results.

It is not possible to use a template with a name dependent on the content of another template.

For example: {{{{tctc}}}} is trying to include a template on a page, using the text in Template:Tctc to get the name of the template. However, {{{{tctc}}}} simply gives the text {{{{tctc}}}}, not the content of the template named in Tctc.

It is not possible to include the content of another template in a parameter value.

For example: {{t-x3|{{tc}}}}, using Template:T-x3, gives Szablon:T-x3. The first pair of end braces is matched to the first pair of start braces (not to the "inner pair" of start braces, as you might expect). Thus, "{{tc" is interpreted as the parameter value.

A template name and a parameter value can both depend on a parameter or variable: {{tt|t|efg}} using Template:Tt, produces "Szablon:Tt", {{{{NAMESPACE}}}}, using Template:Help, gives "{{{{NAMESPACE}}}}".

Template based "case statements"

With a template name depending on a parameter a kind of "case statement" is possible, where data used in multiple cases need to be put only once. With a list of similar case statements, line content that is common to all lines and just differs by case also needs to be put only once for each case, i.e. not for each line separately.

Example 1

Template:Creature demo contains:

[[:Szablon:Creature demo]]

Template:V1 returns the contents of the first variable. Template:V2 returns the contents of the second variable. Template:V3 returns the contents of the third variable.

Thus:

{{creature demo|v1}} gives: Szablon:Creature demo

{{creature demo|v2}} gives: Szablon:Creature demo

{{creature demo|v3}} gives: Szablon:Creature demo

Example 2

For example, a template can be made that, depending on a parameter, produces either just a standard text or also an additional text. This is done by having it call another template, of which the name is a parameter; one version of the other template contains the additional text, the other version is blank.

(Note that a blank page cannot be created directly; first create a non-blank page, e.g. with just one character, then edit the page to blank it. )

Example:

{{variable text demo|full_demo}} gives the long version of a text: Szablon:Variable text demo

while {{variable text demo|short_demo}} gives the short version: Szablon:Variable text demo

This construction uses the following templates:

  • Template:Variable text demo (see wikitext) - a template that produces a list, with, depending on a parameter ("comprehensiveness toggle"), either long versions of all items, or short versions; it contains all data that is not common to all lines
  • Template:Variable line demo - defines the pattern of a list item, including which parts are only in the full version and which also in the short version; it contains the text that is common to all lines
  • the difference between the two versions is obtained with two templates, one for each value of the toggle, and with its name:

Images in templates

New: In a template, image code parameters can contain template parameters, e.g.

{{timgi|wiki|50|small}} {{timgi|wiki|100|medium}} {{timgi|wiki|200|large}}
{{timg1|st|50|pqr}} {{timg1|st|100|st}}

using Template:Timgi and Template:Timg1

gives

Szablon:Timgi Szablon:Timgi Szablon:Timgi Szablon:Timg1 Szablon:Timg1 Szablon:Clr For an image in a template that should be different for each page in which the template occurs, there are also the following possibilities:

  • the whole image code can be a parameter:
{{t|[[Image:Tst.png|thumb|right|50px|bullet]]}}

gives


Szablon:T


  • in projects where external images can be embedded, the url of the image can be a parameter: {{t1|http://meta.wikimedia.org/upload/2/27/Tst.png}} gives Szablon:T1
  • the image is given a name of the form prefix{{PAGENAME}}suffix (with a suffix, consisting of the file name extension and possibly more, and possibly also a prefix), because variables are allowed in image names, but parameters are not. See examples below. Note that changing the name of a page in which the template occurs requires uploading the image again, with the corresponding name.

Templates will break the "Image links" section of the image description page. The methods discussed above will generally fail to show any page in the "Image links". If the specific image is hardcoded into the template, as in Template:timgc, the template will be listed in the "Image links".

Thus for Image:Tst.png the "Image links" section lists Template:Timgc, but neither Template:T nor Template:T1,

Internal links

New: in the case of an internal link in a template with the target depending on a parameter, and in the case of a link with the target depending on a template, existence detection works as usual.

Examples:

New: If, inside the double square brackets, a template is called that produces a text with a pipe character, it is interpreted as such, e.g. [[help:li{{tp}}]] (using Template:tp) gives [[help:liSzablon:Tp]].

External links

With external link style much is possible. A blank space in a parameter value or template content that is substituted in a URL is not taken as ending the URL, but converted to %20.

Examples:

However, a URL can not be composed of:

  • a first part in a parameter and a second part added by the template (although we have seen above that reversed it works: a second part in a parameter and a first part prefixed by the template)
  • a first part in a template and a second part after the template (although we have seen above that reversed it works: the second part in a template and the first part before the template)

Example of first restriction:

Examples of second restriction:

  • [{{th}}add at the end] (using Template:th) gives [[[:Szablon:Th]]add at the end]
  • "{{th}}add at the end" gives "Szablon:Thadd at the end"

Navigational images

The following applies in projects where external images can be embedded.

Examples where the label contains an image and depends on the parameter or template:

With external link style:

Notes:

  • the c and d are used to show the more general case, without them the label is instead of contains an image, with perhaps [[help:link|{{timgurl}}]] giving [[help:link|Szablon:Timgurl]] the more useful kind.
  • the target can be made variable like above.


EasyTimeline code with a template parameter is not allowed

Dyskusja szablonu:Etl

Piped link with parameters

Taking into account the restrictions above, and using Template:Pl, a convenient way of making a piped link with parameters is {{pl|target page|label}}, giving Szablon:Pl. It is equivalent with [[target page|label]], giving label, which only allows parameters in the label and not in the target page name (but one can use the variable PAGENAME there).

In particular target page and label can each be a parameter.

For a really external piped link (also to other Wikimedia projects), use the ordinary [http://target_web_page label], giving label.

If you want to use internal link style but need more flexibility than is possible with the variable PAGENAME, make redirects from the initial target pages to the real ones, e.g. en:Current head of state of Netherlands, resulting from the pagename Netherlands of en:Netherlands.

Interlanguage link (software feature)

A template is not very suitable to put an interlanguage link in: such a link appears in the edge of the page that includes the template, giving the impression that the link is to a version in the other language of the referring page instead of the template. The link label depends only on the sister project that is linked to, not on the page; it is set in the configuration of the project, typically it is the name of the language in that language. The target is only shown in the hover box and the status bar, depending on the browser.

For the same reason pages in the MediaWiki namespace are not very suitable to put an interlanguage link in.

A category tag in a template; caching problem

If a template contains the code indicating that it is in a category, this does not only put that template in the category, but also the pages that include the template. Thus this is typically not applied to categorize templates, but to conveniently put pages in a category, based on the template they use. For example, this page includes Template:Hh and as a result is in Category:English documentation.

The page that contains the template correctly lists the categories to which it belongs. However, adding or deleting a category tag in the template does not add or delete the listings on the category page of pages that use the template, until some edit is made in the page that uses the template.

In other words:

  • lists of categories a page is in, are up-to-date
  • lists of pages in a category are based on the situation just after the last edit of the pages

Since adding or removing a category or template tag is obviously an edit there is only a complication when a page is indirectly added to or deleted from a category, through a change in a template the page uses.

To refresh category pages with respect to the listing of a particular page (adding or deleting the entry), a null edit can be applied to that page: just applying section edit and saving without changes.

Thus, a basic principle of templates, that changing the contents of a template automatically changes the pages that contain the template, does not extend to these pages being correctly listed on category pages. It still works, with a delay, for sets of pages which are all frequently edited anyway, for other purposes.

In other cases the principle is violated. What remains is that just making null edits is somewhat less cumbersome than changing category tags in each page.

Concludingly, adding or deleting a category tag in a template that is already in use should be avoided unless one is willing to make the null edits, or is willing to except the (possibly very long) delay during which there is no consistency between the category pages and the category listing on the pages in the categories.

Caching

When a page in the Template namespace is edited, this automatically clears the cache of any pages which use that template. However, there are cases of indirect dependence where a page may still not be up-to-date, even after pressing Ctrl-F5 or similar. This is e.g. the case for pages (typically template talk pages) referring to en:Template:Tc, containing {{msgnw:{{PAGENAME}}}}, probably because the template page name referred to depends on a variable.

In order to update a page in such cases, use "action=purge", in a URL like http://phpedia.pl/w/index.php?title=Pomoc:Template&action=purge

subst

Putting "subst:" after the double opening braces causes this code in the wikitext to be replaced by the wikitext of the template when the referring page is saved.

Example: {{subst:Box1-demo}} will add the contents of Template:Box1-demo directly to a page.

From version 1.4 subst can have parameters.

If you want to use a modified version of the wikitext in the template, you have to save the page with the unmodified wikitext first, then edit it, because when applying preview the subst code is not yet replaced in the edit box. In the edit summary of the temporary edit you can put "tmp" to indicate that you have not made an error but are still working on the page.

An alternative that clutters the edit history less is, of course, copying the text from the edit box of the template page: then it can be edited before saving. Another method is using msgnw without saving, and copying the preview result into the edit box.

When subst is applied to a template, a variable in the template is copied as such in the wikitext.

Subst can also be applied to a variable itself; this works like applying it to a template. E.g. a timestamp:

{{subst:CURRENTDAY}} {{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}},    {{subst:CURRENTTIME}} (UTC)

giving:

10 March 2005,    08:23 (UTC)

One might be tempted to put this in a template, but then it would display the time of creation of the template; on the other hand, without the "subst:", it would give the time of loading the page with the timestamp. Neither is suitable for a timestamp, which should give the time of saving the new referral to the template (like ~~~~~ does).

Alternatives for subst

  • Use {{..}}, then preview, and copy the result to the edit box, replacing {{..}}. One may prepare a template specially for this usage.
  • Similar, with msgnw.

Redirection

When a page called for inclusion is a redirect page, the redirect target is included instead.

A page that consists of nothing else than the inclusion of another page as a template, shows similarities to a redirect to that other page, but also many differences, including:

  • the result has as header the name of the referring page
  • there is no redirect message
  • the buttons such as edit (for editing the whole page), watch, talk, history, "what links here", etc., refer to the referring page (to go to the target page, a section edit link can be used, from there the whole page can be accessed)
  • the referring page is in the same categories as the target page
  • "double redirects", with one or both being this kind of "pseudo-redirect", work.

Compare Help:Template namespace with Help:Template namespace - demo of alternative for redirect.

In a page that in turn includes such a referring page there is no difference.

Linking to a template

Unfortunately, when linking to a template instead of embedding it, transfer of parameters is not possible. This would be useful e.g. for the following:

Templates in different versions of MediaWiki

Version 1.4

  • Including the same template more than five times in the same page works from version 1.4, now on all Wikimedia sites.

Version 1.3

  • See, among other things, [2].

Version 1.2.6

  • In MediaWiki version 1.2.6, make a page MediaWiki:mytemplate and refer to it with {{msg:mytemplate}}.
  • Compatibility with 1.3, in the sense of having the content in Template:mytemplate, is possible with a redirect from MediaWiki:mytemplate to Template:mytemplate on the 1.2.6 project. The prefix "msg:" in 1.3 is optional and ignored.

Revision history of pages containing templates

Pages in the stored page history consist of wikitext with possible references to templates and images. When viewing an old version of a page, these refer to the current versions of the templates and images, if these still exist. Thus the former composite page is not reconstructed.

Template producing the name of the talk namespace of the calling page

In English language projects the name of a talk namespace is usually simply "{{NAMESPACE}} talk", here giving Pomoc talk. With this a link can be produced: [[{{NAMESPACE}} talk:{{PAGENAME}}]] giving Pomoc talk:Template

In other languages the same or something similar may not be possible. For such cases, see Bug 531 on using templates to effectively create a new variable NAMESPACE_TALK.

Reserved template names

According to the MediaWiki help policy some template names are reserved for use in the Help namespace. This allows copying without modification of the wikitext of help pages across projects. This wikitext contains template tags of the form "{{h:rest of name }}" which allow project-specific content within help pages, using project-specific templates.

Template names referred to by such tags are reserved, follow the link Template:h:f to see the full template name in this project in the case that rest of name is "f ":

  • for English projects with case-insensitivity of the first character: template names starting with "Template:H:".
  • for other projects with case-insensitivity of the first character: template names starting with "Vorlage:H:" and "ModÄ?¨le:H:", etc.
  • for projects with case-sensitivity of the first character: template names starting with "Template:h:", "Vorlage:h:", "ModÄ?¨le:h:", etc.
  • for Hebrew "H:rest of name :" comes to the left of the Hebrew word for template ???ľć?? ć???ľ , see he:Template:h:f, except that if rest of name is the empty string than ":H:" instead of "H::" comes to the left of ???ľć?? ć???ľ , see he:Template:h:. The reserved names are those of which the canonical form of the URL starts with "http://he.wikipedia.org/wiki/%D7%AA%D7%91%D7%A0%D7%99%D7%AA:H:" and similar for the other Hebrew projects.

Note that "case-insensitivity of the first character" refers to the first character after the first colon, not after the second.

See also

Examples

(On each template page, click "What links here" to see the list of pages that use the template.)

Szablon:H:

Szablon:H:g