Help:Templates
| {{{text}}}|Important note: When you edit this page, you agree to release your contribution into the public domain. If you don't want this or can't do this because of license restrictions, please don't edit. This page is one of the Public Domain Help Pages, which can be freely copied into fresh wiki installations and/or distributed with MediaWiki software; see Help:Contents for an overview of all pages. See Project:PD help/Copying for instructions.}} |
If you have standard texts you want to include on several pages, the MediaWiki template feature comes into play.
Creation
Templates are standard wiki pages whose content is designed to be transcluded (embedded) inside other pages. Templates follow a convention that the name is prefixed with codeTemplate:/code, assigning it to that namespace. Therefore you can create them like any other wiki page.
Usage
Templates are wiki pages which can be used in other pages in three ways:
- codenowikiTemplate:Name/nowiki/code 'transcludes' (i.e. includes a copy of) the content of the template (stored in the page nowikiTemplate:Name/nowiki) whenever the page containing the template transclusion is fetched and displayed; i.e. if the template is later changed, the displayed transcluding page will automatically change too
- codenowiki{{subst:Name}}/nowiki/code replaces that string with the contents of the template, in the source of the transcluding page, when you save that page; the copy of the template contents can then be edited normally (and separately from the original in the template page). Note: don't use this if you are looking to continually propagate changes from the source template to the page(s) that references it.
- codenowiki[[:Template:Name]]/nowiki/code includes the template in a form that displays it as raw wiki syntax (the way codenowikilt;nowikigt;/nowiki/code does) when the page containing it is fetched
In fact, an ordinary wiki page can also be used as a template, simply by qualifying the namespace it resides in, so:
- codenowikiTemplate:Pagename/nowiki/code includes codenowikiTemplate:Pagename/nowiki/code
- codenowikiTemplate:Foo:Pagename/nowiki/code includes codenowikiFoo:Pagename/nowiki/code
- codenowikiPagename/nowiki/code includes codenowikiPagename/nowiki/code
If no such namespace exists, the full title is assumed to be a template:
- codenowikiTemplate:Foo:Bar/nowiki/code includes codenowikiTemplate:Foo:Bar/nowiki/code
Parameters
div style=float:right; margin:8px;
| Template with numbered parameters | |
|
prenowiki A little thank you...br / smallfor {{{1}}}.br / hugs, {{{2}}}/small /nowiki/pre | |
| You type | You get |
| codenowiki
/nowiki/code |
|
| with named parameters | |
|
prenowiki A little thank you...br / smallfor {{{reason}}}.br / hugs, {{{signature}}}/small /nowiki/pre | |
| You type | You get |
| prenowiki
/nowiki/pre |
|
/div You can define parameters in templates either numbered as codenowiki{{{1}}}/nowiki/code or named codenowiki{{{param}}}/nowiki/code.
Example: You want a little thank you note you can put on the talk page of other users. It will contain a reason and your signature. You could create Template:Thankyou to enter your text, as in the example in the table.
When using the template on a page, you fill in the parameter values, separated by a pipe char (|): codenowiki
/nowiki/code. For named parameters use name=value pairs separated by a pipe char: codenowiki
/nowiki/code. The advantage of using named parameters in your template is that they are flexible in order. It also makes the template easier to understand if you have many parameters. If you want to change the order of numbered parameters, you have to mention them explicitly: codenowiki
/nowiki/code.
You can also provide default values for parameters, i.e. values that are going to be used if no value is provided for a parameter. For example, codenowikiall your hard work/nowiki/code would result in all your hard work if no value was provided for the parameter ttreason/tt.
Control template inclusion
You can control template inclusion by the use of codenowikinoinclude/nowiki/code and codenowikiincludeonly/nowiki/code tags.
Anything between codenowikinoinclude/nowiki/code and codenowiki/noinclude/nowiki/code will be processed and displayed only when the template's page is being viewed directly.
Possible applications are:
- Categorising templates
- Interlanguage links to similar templates in other languages
- Explanatory text about how to use the template
The converse is codenowikiincludeonly/nowiki/code. Text between codenowikiincludeonly/nowiki/code and codenowiki/includeonly/nowiki/code will be processed and displayed only when the page is being included. The obvious application is to add all pages containing a given template to a category, without putting the template itself into that category.
Note: when you change the categories applied by a template, the categorization of the pages that use that template may not be updated until some time later: this is handled by the {{ #ifeq:
tighar.org
| www.mediawiki.org | job queue | job queue }}.
Organizing templates
For templates to be effective users need to find them and be able to use them. A simple technique is to include an example on the template page. For example: div style=display:table; width:auto;pre noinclude
Usage
Allows to establish a link to a subject: nowikiTemplate:NameOfTemplate/nowiki /noinclude /pre/div
Then, an editor can simply copy and paste the example to create a similar page.
Copying from one wiki to another
Templates often require CSS or other templates, so users frequently have trouble copying templates from one wiki to another. The steps below should work for most templates:
- Copy the template text to the new wiki, either by importing or with a link in the edit summary to the original page (for attribution).
- Look for CSS classes (like class=foobar) in the template text. If those classes appear in MediaWiki:Common.css or MediaWiki:Monobook.css on the original wiki, copy them to MediaWiki:Common.css on the new wiki.
- Look for templates (like nowikiTemplate:Foobar/nowiki) inside the template text, and copy those templates to the new wiki.
- If the template uses ParserFunctions, you must install the {{ #ifeq:
tighar.org
| www.mediawiki.org | ParserFunctions extension | ParserFunctions extension }}.
See Also
- Help:External searches – a template special use case example
- Help:Magic words – fancy stuff you may find in some templates
- {{ #ifeq:
tighar.org
| www.mediawiki.org | meta:Help:Embed page | meta:Help:Embed page }} – embedding pages from {{ #ifeq:
tighar.org
| www.mediawiki.org | namespaces | namespaces }} other than codeTemplate:/code.
| {{#switch:Templates |=Languages: |Languages=Languages: |MediaWiki=Languages: |af=Taal: |ar=:اللغة |bcc=:زبان |bg=Език: |br=Yezh : |ca=Llengua: |cs=Jazyk: |da=Sprog: |de=Sprache: |el=Γλώσσα: |en=Language: |ru=Язык: |#default=Language: }} |
English {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/af | • {{#if: Help:Templates|Afrikaans| Afrikaans}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/ar | • {{#if: Help:Templates|العربية| العربية}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/az | • {{#if: Help:Templates|azərbaycanca| azərbaycanca}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/bcc | • {{#if: Help:Templates|جهلسری بلوچی| جهلسری بلوچی}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/bg | • {{#if: Help:Templates|български| български}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/br | • {{#if: Help:Templates|brezhoneg| brezhoneg}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/ca | • {{#if: Help:Templates|català| català}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/cs | • {{#if: Help:Templates|čeština| čeština}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/da | • {{#if: Help:Templates|dansk| dansk}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/de | • {{#if: Help:Templates|Deutsch| Deutsch}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/el | • {{#if: Help:Templates|Ελληνικά| Ελληνικά}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/es | • {{#if: Help:Templates|español| español}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/fa | • {{#if: Help:Templates|فارسی| فارسی}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/fi | • {{#if: Help:Templates|suomi| suomi}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/fr | • {{#if: Help:Templates|français| français}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/gl | • {{#if: Help:Templates|galego| galego}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/gu | • {{#if: Help:Templates|ગુજરાતી| ગુજરાતી}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/he | • {{#if: Help:Templates|עברית| עברית}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/hu | • {{#if: Help:Templates|magyar| magyar}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/id | • {{#if: Help:Templates|Bahasa Indonesia| Bahasa Indonesia}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/it | • {{#if: Help:Templates|italiano| italiano}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/ja | • {{#if: Help:Templates|日本語| 日本語}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/ka | • {{#if: Help:Templates|ქართული| ქართული}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/ko | • {{#if: Help:Templates|한국어| 한국어}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/ksh | • {{#if: Help:Templates|Ripoarisch| Ripoarisch}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/ml | • {{#if: Help:Templates|മലയാളം| മലയാളം}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/mr | • {{#if: Help:Templates|मराठी| मराठी}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/ms | • {{#if: Help:Templates|Bahasa Melayu| Bahasa Melayu}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/nl | • {{#if: Help:Templates|Nederlands| Nederlands}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/no | • {{#if: Help:Templates|norsk| norsk}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/oc | • {{#if: Help:Templates|occitan| occitan}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/pl | • {{#if: Help:Templates|polski| polski}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/pt | • {{#if: Help:Templates|português| português}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/ro | • {{#if: Help:Templates|română| română}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/ru | • {{#if: Help:Templates|русский| русский}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/si | • {{#if: Help:Templates|සිංහල| සිංහල}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/sk | • {{#if: Help:Templates|slovenčina| slovenčina}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/sq | • {{#if: Help:Templates|shqip| shqip}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/sr | • {{#if: Help:Templates|српски / srpski| српски / srpski}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/sv | • {{#if: Help:Templates|svenska| svenska}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/ta | • {{#if: Help:Templates|தமிழ்| தமிழ்}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/th | • {{#if: Help:Templates|ไทย| ไทย}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/tr | • {{#if: Help:Templates|Türkçe| Türkçe}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/uk | • {{#if: Help:Templates|українська| українська}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/vi | • {{#if: Help:Templates|Tiếng Việt| Tiếng Việt}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/yue | • {{#if: Help:Templates|粵語| 粵語}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/zh | • {{#if: Help:Templates|中文| 中文}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/zh-hans | • {{#if: Help:Templates|中文(简体)| 中文(简体)}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/zh-hant | • {{#if: Help:Templates|中文(繁體)| 中文(繁體)}}|}} {{#ifexist: {{#if: Help:Templates | Help:Templates | {{#if: Help | Help:}}Templates}}/zh-tw | • {{#if: Help:Templates|中文(臺灣)| 中文(臺灣)}}|}} |
