Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
MainPage
Community portal
Recent changes
Random page
Help
Special pages
Donate
Search
Search
English
Appearance
Log in
Request account
Personal tools
Log in
Request account
Export translations
Translate
English
Language statistics
Message group statistics
Export
Tools
Tools
move to sidebar
hide
Actions
Language statistics
Message group statistics
Export
General
Printable version
In other projects
Appearance
move to sidebar
hide
Settings
Group
Category:Maintenance
Help:Blocking users
Help:Bots
Help:Categories
Help:Contents
Help:Deletion and undeletion
Help:Diff
Help:Editing pages
Help:ExpandTemplates
Help:Extension:ParserFunctions
Help:External searches
Help:Formatting
Help:Images
Help:Links
Help:Magic words
Help:Managing files
Help:Moving a page
Help:Namespaces
Help:Navigation
Help:Parser functions in templates
Help:Patrolled edits
Help:Preferences
Help:Protected pages
Help:Random page
Help:Random root page
Help:Range blocks
Help:Recent changes
Help:Redirects
Help:Skins
Help:Special pages
Help:Starting a new page
Help:Substitution
Help:System message
Help:Tables
Help:Talk pages
Help:TemplateData
Help:Templates
Help:TemplateStyles
Help:Tracking changes
Help:Undelete
Help:User contributions
Help:Watchlist
Help:What links here
Manual:Expr parser function syntax
Manual:Extending wiki markup
Manual:Hooks
Manual:Magic words
Manual:Messages API
Manual:Parser functions
Module:Arguments/doc
Module:Int/doc
Module:Message box/configuration/doc
Module:Message box/doc
Module:Template translation/doc
Module:Transcluder/doc
Module:Version/doc
Module:Yesno/doc
Parser extension tags
Parser function extensions
Project:Language policy
Template:Admin tip
Template:Advanced user manual
Template:Anontools
Template:ApiEx
Template:Autocat
Template:Auxiliary template common notice
Template:Branching
Template:Bugfix
Template:Bugzilla
Template:Button
Template:Candidate
Template:Caution
Template:Clarify
Template:Collapse top
Template:Component
Template:Deprecated-inline
Template:Description missing
Template:Distinguish
Template:Documentation
Template:Documentation subpage
Template:Done
Template:EmptyCatGood
Template:Escape template list
Template:Excerpt
Template:Extension development
Template:Fixtext
Template:For
Template:Further
Template:Help
Template:High-risk
Template:Historical
Template:I18n navigation
Template:In progress
Template:Intricate template
Template:Introduced-inline
Template:IRC
Template:Localized link
Template:Localized link/messagedoc
Template:Magic words
Template:Main
Template:MainPage
Template:Markup
Template:Markup/row
Template:Mbox templates
Template:Module rating
Template:Move
Template:MW version
Template:MW version/layout
Template:N/a
Template:Navbar
Template:Newarticletext
Template:No
Template:Not done
Template:Note
Template:Optional
Template:Parser functions nav
Template:Partially done
Template:PD Help Page
Template:Phabricator
Template:Ptag
Template:Purge
Template:Recentchangestext
Template:Removed-inline
Template:Required
Template:Rev
Template:Security
Template:See
Template:See also
Template:Sp-contributions-footer
Template:Sp-contributions-footer-anon
Template:Special page
Template:Template shortcut
Template:Template test cases notice
Template:TemplateData header
Template:Thankyou
Template:To do
Template:Tracked
Template:Translatable
Template:Translatable template name
Template:Unusedtemplatestext
Template:Update
Template:Used in system
Template:Watchlists navigation
Template:Why
Template:WikiNonStop News
Template:Yes
TemplateData
Language
aa - Afar
aae - Arbëresh
ab - Abkhazian
abr - Abron
abs - Ambonese Malay
ace - Acehnese
acf - Saint Lucian Creole
acm - Iraqi Arabic
ady - Adyghe
ady-cyrl - Adyghe (Cyrillic script)
aeb - Tunisian Arabic
aeb-arab - Tunisian Arabic (Arabic script)
aeb-latn - Tunisian Arabic (Latin script)
af - Afrikaans
aig - Antiguan and Barbudan Creole English
aln - Gheg Albanian
alt - Southern Altai
am - Amharic
ami - Amis
an - Aragonese
ang - Old English
ann - Obolo
anp - Angika
apc - Levantine Arabic
ar - Arabic
arc - Aramaic
arn - Mapuche
arq - Algerian Arabic
ary - Moroccan Arabic
arz - Egyptian Arabic
as - Assamese
ase - American Sign Language
ast - Asturian
atj - Atikamekw
av - Avaric
avk - Kotava
awa - Awadhi
ay - Aymara
az - Azerbaijani
azb - South Azerbaijani
ba - Bashkir
ban - Balinese
ban-bali - Balinese (Balinese script)
bar - Bavarian
bbc - Batak Toba
bbc-latn - Batak Toba (Latin script)
bcc - Southern Balochi
bci - Baoulé
bcl - Central Bikol
bdr - West Coast Bajau
be - Belarusian
be-tarask - Belarusian (Taraškievica orthography)
bew - Betawi
bg - Bulgarian
bgc - Haryanvi
bgn - Western Balochi
bh - Bhojpuri
bho - Bhojpuri
bi - Bislama
bjn - Banjar
blk - Pa'O
bm - Bambara
bn - Bangla
bo - Tibetan
bpy - Bishnupriya
bqi - Bakhtiari
br - Breton
brh - Brahui
bs - Bosnian
btm - Batak Mandailing
bto - Rinconada Bikol
bug - Buginese
bug-bugi - Buginese (Buginese script)
bxr - Russia Buriat
ca - Catalan
cbk-zam - Chavacano
ccp - Chakma
cdo - Mindong
cdo-hant - Mindong (Traditional Han script)
cdo-latn - Mindong (Latin script)
ce - Chechen
ceb - Cebuano
ch - Chamorro
chn - Chinook Jargon
cho - Choctaw
chr - Cherokee
chy - Cheyenne
ckb - Central Kurdish
co - Corsican
cop - Coptic
cps - Capiznon
cpx - Puxian
cpx-hans - Puxian (Simplified Han script)
cpx-hant - Puxian (Traditional Han script)
cpx-latn - Puxian (Latin script)
cr - Cree
crh - Crimean Tatar
crh-cyrl - Crimean Tatar (Cyrillic script)
crh-latn - Crimean Tatar (Latin script)
crh-ro - Dobrujan Tatar
cs - Czech
csb - Kashubian
cu - Church Slavic
cv - Chuvash
cy - Welsh
da - Danish
dag - Dagbani
de - German
de-at - Austrian German
de-ch - Swiss High German
de-formal - German (formal address)
dga - Southern Dagaare
din - Dinka
diq - Dimli
dlg - Dolgan
dsb - Lower Sorbian
dtp - Central Dusun
dty - Doteli
dua - Duala
dv - Divehi
dz - Dzongkha
ee - Ewe
efi - Efik
egl - Emilian
el - Greek
eml - Emiliano-Romagnolo
en - English
en-ca - Canadian English
en-gb - British English
eo - Esperanto
es - Spanish
es-419 - Latin American Spanish
es-formal - Spanish (formal address)
et - Estonian
eu - Basque
ext - Extremaduran
fa - Persian
fat - Fanti
ff - Fula
fi - Finnish
fit - Tornedalen Finnish
fj - Fijian
fo - Faroese
fon - Fon
fr - French
frc - Cajun French
frp - Arpitan
frr - Northern Frisian
fur - Friulian
fvr - Fur
fy - Western Frisian
ga - Irish
gaa - Ga
gag - Gagauz
gan - Gan
gan-hans - Gan (Simplified Han script)
gan-hant - Gan (Traditional Han script)
gcf - Guadeloupean Creole
gcr - Guianan Creole
gd - Scottish Gaelic
gl - Galician
gld - Nanai
glk - Gilaki
gn - Guarani
gom - Goan Konkani
gom-deva - Goan Konkani (Devanagari script)
gom-latn - Goan Konkani (Latin script)
gor - Gorontalo
got - Gothic
gpe - Ghanaian Pidgin
grc - Ancient Greek
gsw - Alemannic
gu - Gujarati
guc - Wayuu
gur - Frafra
guw - Gun
gv - Manx
ha - Hausa
hak - Hakka Chinese
hak-hans - Hakka (Simplified Han script)
hak-hant - Hakka (Traditional Han script)
hak-latn - Hakka (Latin script)
haw - Hawaiian
he - Hebrew
hi - Hindi
hif - Fiji Hindi
hif-latn - Fiji Hindi (Latin script)
hil - Hiligaynon
hke - Hunde
hno - Northern Hindko
ho - Hiri Motu
hoc-latn - Ho (Latin script)
hr - Croatian
hrx - Hunsrik
hsb - Upper Sorbian
hsn - Xiang
ht - Haitian Creole
hu - Hungarian
hu-formal - Hungarian (formal address)
hy - Armenian
hyw - Western Armenian
hz - Herero
ia - Interlingua
iba - Iban
ibb - Ibibio
id - Indonesian
ie - Interlingue
ig - Igbo
igl - Igala
ii - Sichuan Yi
ik - Inupiaq
ike-cans - Eastern Canadian (Aboriginal syllabics)
ike-latn - Eastern Canadian (Latin script)
ilo - Iloko
inh - Ingush
io - Ido
is - Icelandic
isv-cyrl - Interslavic (Cyrillic script)
isv-latn - Interslavic (Latin script)
it - Italian
iu - Inuktitut
ja - Japanese
jam - Jamaican Creole English
jbo - Lojban
jut - Jutish
jv - Javanese
ka - Georgian
kaa - Kara-Kalpak
kab - Kabyle
kai - Karekare
kaj - Jju
kbd - Kabardian
kbd-cyrl - Kabardian (Cyrillic script)
kbp - Kabiye
kcg - Tyap
kea - Kabuverdianu
kg - Kongo
kge - Komering
khw - Khowar
ki - Kikuyu
kiu - Kirmanjki
kj - Kuanyama
kjh - Khakas
kjp - Eastern Pwo
kk - Kazakh
kk-arab - Kazakh (Arabic script)
kk-cn - Kazakh (China)
kk-cyrl - Kazakh (Cyrillic script)
kk-kz - Kazakh (Kazakhstan)
kk-latn - Kazakh (Latin script)
kk-tr - Kazakh (Turkey)
kl - Kalaallisut
km - Khmer
kn - Kannada
knc - Central Kanuri
ko - Korean
ko-kp - Korean (North Korea)
koi - Komi-Permyak
kr - Kanuri
krc - Karachay-Balkar
kri - Krio
krj - Kinaray-a
krl - Karelian
ks - Kashmiri
ks-arab - Kashmiri (Arabic script)
ks-deva - Kashmiri (Devanagari script)
ksh - Colognian
ksw - S'gaw Karen
ku - Kurdish
ku-arab - Kurdish (Arabic script)
ku-latn - Kurdish (Latin script)
kum - Kumyk
kus - Kusaal
kv - Komi
kw - Cornish
ky - Kyrgyz
la - Latin
lad - Ladino
lb - Luxembourgish
lbe - Lak
lez - Lezghian
lfn - Lingua Franca Nova
lg - Ganda
li - Limburgish
lij - Ligurian
liv - Livonian
ljp - Lampung Api
lki - Laki
lld - Ladin
lmo - Lombard
ln - Lingala
lo - Lao
loz - Lozi
lrc - Northern Luri
lt - Lithuanian
ltg - Latgalian
lua - Luba-Lulua
lus - Mizo
luz - Southern Luri
lv - Latvian
lzh - Literary Chinese
lzz - Laz
mad - Madurese
mag - Magahi
mai - Maithili
map-bms - Banyumasan
mdf - Moksha
mg - Malagasy
mh - Marshallese
mhr - Eastern Mari
mi - Māori
min - Minangkabau
mk - Macedonian
ml - Malayalam
mn - Mongolian
mnc - Manchu
mnc-latn - Manchu (Latin script)
mnc-mong - Manchu (Mongolian script)
mni - Manipuri
mnw - Mon
mo - Moldovan
mos - Mossi
mr - Marathi
mrh - Mara
mrj - Western Mari
ms - Malay
ms-arab - Malay (Jawi script)
mt - Maltese
mui - Musi
mus - Muscogee
mwl - Mirandese
my - Burmese
myv - Erzya
mzn - Mazanderani
na - Nauru
nah - Nahuatl
nan - Minnan
nan-hant - Minnan (Traditional Han script)
nan-latn-pehoeji - Minnan (Pe̍h-ōe-jī)
nan-latn-tailo - Minnan (Tâi-lô)
nap - Neapolitan
nb - Norwegian Bokmål
nds - Low German
nds-nl - Low Saxon
ne - Nepali
new - Newari
ng - Ndonga
nia - Nias
nit - Southeastern Kolami
niu - Niuean
nl - Dutch
nl-informal - Dutch (informal address)
nmz - Nawdm
nn - Norwegian Nynorsk
no - Norwegian
nod - Northern Thai
nog - Nogai
nov - Novial
nqo - N’Ko
nr - South Ndebele
nrm - Norman
nso - Northern Sotho
nup - Nupe
nv - Navajo
ny - Nyanja
nyn - Nyankole
nyo - Nyoro
nys - Nyungar
oc - Occitan
ojb - Northwestern Ojibwa
olo - Livvi-Karelian
om - Oromo
or - Odia
os - Ossetic
pa - Punjabi
pag - Pangasinan
pam - Pampanga
pap - Papiamento
pap-aw - Papiamento (Aruba)
pcd - Picard
pcm - Nigerian Pidgin
pdc - Pennsylvania German
pdt - Plautdietsch
pfl - Palatine German
pi - Pali
pih - Pitcairn-Norfolk
pl - Polish
pms - Piedmontese
pnb - Western Punjabi
pnt - Pontic
prg - Prussian
ps - Pashto
pt - Portuguese
pt-br - Brazilian Portuguese
pwn - Paiwan
qqq - Message documentation
qu - Quechua
qug - Chimborazo Highland Quichua
rgn - Romagnol
rif - Riffian
rki - Arakanese
rm - Romansh
rmc - Carpathian Romani
rmy - Vlax Romani
rn - Rundi
ro - Romanian
roa-tara - Tarantino
rsk - Pannonian Rusyn
ru - Russian
rue - Rusyn
rup - Aromanian
ruq - Megleno-Romanian
ruq-cyrl - Megleno-Romanian (Cyrillic script)
ruq-latn - Megleno-Romanian (Latin script)
rut - Rutul
rw - Kinyarwanda
ryu - Okinawan
sa - Sanskrit
sah - Yakut
sas - Sasak
sat - Santali
sc - Sardinian
scn - Sicilian
sco - Scots
sd - Sindhi
sdc - Sassarese Sardinian
sdh - Southern Kurdish
se - Northern Sami
se-fi - Northern Sami (Finland)
se-no - Northern Sami (Norway)
se-se - Northern Sami (Sweden)
sei - Seri
ses - Koyraboro Senni
sg - Sango
sgs - Samogitian
sh - Serbo-Croatian
sh-cyrl - Serbo-Croatian (Cyrillic script)
sh-latn - Serbo-Croatian (Latin script)
shi - Tachelhit
shi-latn - Tachelhit (Latin script)
shi-tfng - Tachelhit (Tifinagh script)
shn - Shan
shy - Shawiya
shy-latn - Shawiya (Latin script)
si - Sinhala
simple - Simple English
sjd - Kildin Sami
sje - Pite Sami
sk - Slovak
skr - Saraiki
skr-arab - Saraiki (Arabic script)
sl - Slovenian
sli - Lower Silesian
sm - Samoan
sma - Southern Sami
smn - Inari Sami
sms - Skolt Sami
sn - Shona
so - Somali
sq - Albanian
sr - Serbian
sr-ec - Serbian (Cyrillic script)
sr-el - Serbian (Latin script)
srn - Sranan Tongo
sro - Campidanese Sardinian
ss - Swati
st - Southern Sotho
stq - Saterland Frisian
sty - Siberian Tatar
su - Sundanese
sv - Swedish
sw - Swahili
syl - Sylheti
szl - Silesian
szy - Sakizaya
ta - Tamil
tay - Atayal
tcy - Tulu
tdd - Tai Nuea
te - Telugu
tet - Tetum
tg - Tajik
tg-cyrl - Tajik (Cyrillic script)
tg-latn - Tajik (Latin script)
th - Thai
ti - Tigrinya
tig - Tigre
tk - Turkmen
tl - Tagalog
tly - Talysh
tly-cyrl - Talysh (Cyrillic script)
tn - Tswana
to - Tongan
tok - Toki Pona
tpi - Tok Pisin
tr - Turkish
tru - Turoyo
trv - Taroko
ts - Tsonga
tt - Tatar
tt-cyrl - Tatar (Cyrillic script)
tt-latn - Tatar (Latin script)
ttj - Tooro
tum - Tumbuka
tw - Twi
ty - Tahitian
tyv - Tuvinian
tzm - Central Atlas Tamazight
udm - Udmurt
ug - Uyghur
ug-arab - Uyghur (Arabic script)
ug-latn - Uyghur (Latin script)
uk - Ukrainian
ur - Urdu
uz - Uzbek
uz-cyrl - Uzbek (Cyrillic script)
uz-latn - Uzbek (Latin script)
ve - Venda
vec - Venetian
vep - Veps
vi - Vietnamese
vls - West Flemish
vmf - Main-Franconian
vmw - Makhuwa
vo - Volapük
vot - Votic
vro - Võro
wa - Walloon
wal - Wolaytta
war - Waray
wls - Wallisian
wlx - Wali
wo - Wolof
wuu - Wu
wuu-hans - Wu (Simplified Han script)
wuu-hant - Wu (Traditional Han script)
xal - Kalmyk
xh - Xhosa
xmf - Mingrelian
xsy - Saisiyat
yi - Yiddish
yo - Yoruba
yrl - Nheengatu
yua - Yucatec Maya
yue - Cantonese
yue-hans - Cantonese (Simplified Han script)
yue-hant - Cantonese (Traditional Han script)
za - Zhuang
zea - Zeelandic
zgh - Standard Moroccan Tamazight
zgh-latn - Standard Moroccan Tamazight (Latin script)
zh - Chinese
zh-cn - Chinese (China)
zh-hans - Simplified Chinese
zh-hant - Traditional Chinese
zh-hk - Chinese (Hong Kong)
zh-mo - Chinese (Macau)
zh-my - Chinese (Malaysia)
zh-sg - Chinese (Singapore)
zh-tw - Chinese (Taiwan)
zu - Zulu
Format
Export for off-line translation
Export in native format
Export in CSV format
Fetch
<languages/> {{PD Help Page}} <span lang="en" dir="ltr" class="mw-content-ltr">If you have standard texts you want to include on several pages, the MediaWiki '''template''' feature comes into play.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Unlike {{ll|Manual:Extensions|extensions}} and {{ll|Help:Images|media files}}, there is no central repository for templates.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Templates can be newly written or, to save duplicating work already done, exported from another wiki e.g. Wikipedia, and then imported into the target wiki.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> == Basic usage == </div> <span lang="en" dir="ltr" class="mw-content-ltr">Templates are standard wiki pages whose content is designed to be '''[[Special:MyLanguage/Transclusion|transcluded]]''' (embedded) inside other pages.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Templates follow a convention that the name is prefixed with "<code>Template:</code>", assigning it to the [[Special:MyLanguage/Help:Namespaces|template namespace]]; besides this, you can [[Special:MyLanguage/Help:Starting a new page|create them like any other wiki page]].</span> <div lang="en" dir="ltr" class="mw-content-ltr"> To transclude a template, you use double opening & closing curly brackets {{tmpl|0=<code><nowiki>{{</nowiki>$1<nowiki>}}</nowiki></code>|template name}}. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> The simplest use of templates is as follows: Create a page called <code>Template:Welcome</code> with the content below: </div> <span lang="en" dir="ltr" class="mw-content-ltr">Hello! Welcome to the wiki.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> You have created your first template! Now, insert the code below in a new page: </div> <nowiki>{{Welcome}}</nowiki> <div lang="en" dir="ltr" class="mw-content-ltr"> When the new page is viewed, the text "Hello! Welcome to the wiki." will appear instead of <code><nowiki>{{Welcome}}</nowiki></code>. The template content is '''transcluded''' into the other page, i.e., it is integrated in the page. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> You can then insert <code><nowiki>{{Welcome}}</nowiki></code> at any point of any page where you wish to welcome someone. Suppose it is used in 100 pages. If you then change the template contents to: </div> <span lang="en" dir="ltr" class="mw-content-ltr">Hi there! Welcome to this wonderful wiki.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> And revisit any of the 100 pages where the template was used, you'll see the new text instead of the original one. In this way, you have changed the content of 100 pages without editing them, because the template is transcluded into these pages. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> This is the basic mechanism. There are several additional features of transclusion that enrich this mechanism and make templates very useful. </div> {{anchor|Usage}} <div lang="en" dir="ltr" class="mw-content-ltr"> == Ways to invoke a template == </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Templates can be used in other pages in these ways: </div> <div lang="en" dir="ltr" class="mw-content-ltr"> * <code><nowiki>{{Name}}</nowiki></code> – As described above, this text (commonly referred to as a "template call") will be ''dynamically'' replaced by the content of the page titled Template:Name (a process called "transclusion") every time the page with the template call is '''loaded''' (i.e., viewed by a reader of the wiki). </div> <span lang="en" dir="ltr" class="mw-content-ltr">Because the template call remains in the pages's source, any subsequent change to Template:Name will be seen on the page containing the template call.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Also, the page will be listed among those that "link to" the template.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> * <code><nowiki>{{subst:Name}}</nowiki></code> – When this type of template call is used, it will be replaced by a ''static copy'' of the content of Template:Name as of the time the page containing the template call is '''saved'''. </div> <span lang="en" dir="ltr" class="mw-content-ltr">That is, a copy of the contents of Template:Name will be ''substituted'' for the template call.</span> <span lang="en" dir="ltr" class="mw-content-ltr">No link is maintained between the page and the template, so each can be edited further without affecting the other.</span> <span lang="en" dir="ltr" class="mw-content-ltr">In effect, there is little difference between substituting the content in this way and simply typing it into the page's source "manually".</span> <span lang="en" dir="ltr" class="mw-content-ltr">See {{ll|Help:Substitution}} for more information.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> * {{tmpl|0=<code><nowiki>{{</nowiki>safesubst:$1<nowiki>}}</nowiki></code>|Name}} – This was introduced to allow for recursive substitution in cases where templates contain calls to other templates or parser functions. </div> <span lang="en" dir="ltr" class="mw-content-ltr">See {{ll|Help:Substitution}} for more information.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> * {{tmpl|0=<code><nowiki>{{</nowiki>msgnw:$1<nowiki>}}</nowiki></code>|Name}} – This displays the template content as raw wiki syntax (the way {{tag|nowiki|open}} does) when the page containing it is viewed. </div> <span lang="en" dir="ltr" class="mw-content-ltr">For example, <code><nowiki>{{msgnw:Template:Thankyou}}</nowiki></code> displays:</span> {{msgnw:{{#ifexist:Template:Thankyou/{{PAGELANGUAGE}}|Template:Thankyou/{{PAGELANGUAGE}}|Template:Thankyou}}}} <div lang="en" dir="ltr" class="mw-content-ltr"> In fact, an ordinary wiki page can also be used as a template, simply by specifying the namespace it resides in, so: </div> * <span lang="en" dir="ltr" class="mw-content-ltr"><code><nowiki>{{Template:Pagename}}</nowiki></code> transcludes the page titled Template:Pagename (equivalent to <code><nowiki>{{Pagename}}</nowiki></code>)</span> * <span lang="en" dir="ltr" class="mw-content-ltr"><code><nowiki>{{Talk:Pagename}}</nowiki></code> transcludes the page titled Talk:Pagename</span> * <span lang="en" dir="ltr" class="mw-content-ltr"><code><nowiki>{{:Pagename}}</nowiki></code> transcludes the page titled Pagename (i.e., in the main namespace)</span> ** <span lang="en" dir="ltr" class="mw-content-ltr"><code><nowiki>{{subst::Pagename}}</nowiki></code> substitutes the contents of the page titled Pagename</span> <div lang="en" dir="ltr" class="mw-content-ltr"> If the specified namespace doesn't exist, the full title is assumed to be a template: </div> <div lang="en" dir="ltr" class="mw-content-ltr"> * <code><nowiki>{{Foo:Bar}}</nowiki></code> transcludes Template:Foo:Bar </div> <span lang="en" dir="ltr" class="mw-content-ltr">Regardless of what syntax is used, the name of the template can be relative to the current page</span> {{tmpl|0=<span lang="en" dir="ltr" class="mw-content-ltr">For example, if <code>{{((}}/$2{{))}}</code> is called on page $1, it will transclude the page $1/$2.</span> |1=<span lang="en" dir="ltr" class="mw-content-ltr">foo</span> |2=<span lang="en" dir="ltr" class="mw-content-ltr">bar</span> }} <span lang="en" dir="ltr" class="mw-content-ltr">It can also be generated dynamically.</span> {{tmpl|0=<span lang="en" dir="ltr" class="mw-content-ltr">For example, <code>{{ {{((}}$1{{))}} }}</code> calls Template:$1 and interprets the result as the name of another template to call.</span> |1=<span lang="en" dir="ltr" class="mw-content-ltr">foo</span> }} <div lang="en" dir="ltr" class="mw-content-ltr"> == Parameters == </div> <div lang="en" dir="ltr" class="mw-content-ltr"> To enrich the mechanism of transclusion, MediaWiki allows parameters to be passed to a template when it is transcluded. Parameters allow the template to produce different contents or have different behaviors. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Suppose you wish to insert a little thank you note in the [[Special:MyLanguage/Help:Talk pages|talk page]] of other users, such as: </div> <div lang="en" dir="ltr" class="mw-content-ltr"> {{Thankyou|all your effort|Me}} </div> <div lang="en" dir="ltr" class="mw-content-ltr"> The thank you note will have a reason (in this case, "all your effort") and a signature ("Me"). Your objective is for any user to be able to thank any other user, for any reason whatsoever. </div> <span lang="en" dir="ltr" class="mw-content-ltr">So that the note will look similar everywhere it is used, you can define a template called {{ll|Template:Thankyou}}, for example.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Although the note should look similar whenever a user thanks another user, its specific contents (i.e., the reason and the signature) will be different.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For that reason, you should pass them as parameters.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If we ignore the remaining elements to format the box and place the image, the core content of the template will be this:</span> <syntaxhighlight lang="wikitext"> '''A little thank you...''' for {{{1}}}. Hugs, {{{2}}} </syntaxhighlight> <div lang="en" dir="ltr" class="mw-content-ltr"> Notice the use of <code><nowiki>{{{1}}}</nowiki></code> and <code><nowiki>{{{2}}}</nowiki></code>. This is the way to identify, within templates, the parameters that will be passed in when the template is used. Note that, within the template, each parameter is surrounded by '''three''' braces: <code><nowiki>{{{ }}}</nowiki></code>. This is different from normal template name usage. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> When using the template on a page, you fill in the parameter values, separated by a "pipe" character (<code>|</code>). MediaWiki allows parameters to be passed to the template in three ways: Anonymously, Numbered, and Named. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> === Anonymous parameters === </div> <div lang="en" dir="ltr" class="mw-content-ltr"> To pass in anonymous parameters, list the values of those parameters sequentially: </div> <span lang="en" dir="ltr" class="mw-content-ltr"><nowiki>{{Thankyou|all your effort|Me}}</nowiki></span> <div lang="en" dir="ltr" class="mw-content-ltr"> In this case, the <code><nowiki>{{Thankyou}}</nowiki></code> template receives parameters <code><nowiki>{{{1}}}=all your effort</nowiki></code> and <code><nowiki>{{{2}}}=Me</nowiki></code>, producing: </div> <div lang="en" dir="ltr" class="mw-content-ltr"> {{Thankyou|all your effort|Me}} </div> <div lang="en" dir="ltr" class="mw-content-ltr"> The order in which anonymous parameters are passed in is crucial to its behavior. Reversing the order of the parameters, like so: </div> <span lang="en" dir="ltr" class="mw-content-ltr"><nowiki>{{Thankyou|Me|all your effort}}</nowiki></span> <div lang="en" dir="ltr" class="mw-content-ltr"> would produce this result: </div> <div lang="en" dir="ltr" class="mw-content-ltr"> {{Thankyou|Me|all your effort}} </div> {{note|1=<span lang="en" dir="ltr" class="mw-content-ltr">Identifying parameters by order (with <code><nowiki>{{{1}}}</nowiki></code>, etc.) works ''only'' with anonymous parameters.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Any parameters identified by name, as shown below, will not be accessible to the template using ordinal numbers.</span>}} {{note|1=<span lang="en" dir="ltr" class="mw-content-ltr">If an equal sign appears inside the argument to an anonymous template parameter, that parameter may be misinterpreted as a [[#Named parameters|named parameter]] (which is explained below in this document) treating the text before the equal sign as the parameter name and the text after it as the argument value.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This is a common problem when you need to include an external link, or an HTML element with attributes (see {{task|T16235}}).</span> <span lang="en" dir="ltr" class="mw-content-ltr">The workaround is to use named parameters instead, or even numbered parameters as explained in the following section.</span>}} <div lang="en" dir="ltr" class="mw-content-ltr"> === Numbered parameters === </div> <div lang="en" dir="ltr" class="mw-content-ltr"> To pass in parameters by number, identify each parameter when passing it: </div> <span lang="en" dir="ltr" class="mw-content-ltr"><nowiki>{{Thankyou|2=Me|1=your friendship}}</nowiki></span> <div lang="en" dir="ltr" class="mw-content-ltr"> This time, template <code><nowiki>{{Thankyou}}</nowiki></code> receives parameters <code><nowiki>{{{1}}}=your friendship</nowiki></code> and <code><nowiki>{{{2}}}=Me</nowiki></code>, though they have been supplied in inverse order, and produces: </div> <div lang="en" dir="ltr" class="mw-content-ltr"> {{Thankyou|2=Me|1=your friendship}} </div> {{note|1=<span lang="en" dir="ltr" class="mw-content-ltr">This may also be useful when any of the numbered parameters contains an "=" sign.</span>}} ;<span lang="en" dir="ltr" class="mw-content-ltr">Examples:</span> <pre>{{Thankyou|1=adding "="|2=Me}}</pre> <span lang="en" dir="ltr" class="mw-content-ltr">produces:</span> <span lang="en" dir="ltr" class="mw-content-ltr">{{Thankyou|1=adding "="|2=Me}}</span> {{note|1=<span lang="en" dir="ltr" class="mw-content-ltr">This also requires that the unnamed parameters be numbered, i.e. <code>1=</code>, <code>2=</code>.</span>}} <div lang="en" dir="ltr" class="mw-content-ltr"> === Named parameters === </div> <div lang="en" dir="ltr" class="mw-content-ltr"> The third way of passing parameters is by name instead of numbers. In this case, the template contents would be changed to: </div> <syntaxhighlight lang="wikitext">'''A little thank you...''' for {{{reason}}}. Hugs, {{{signature}}}</syntaxhighlight> <div lang="en" dir="ltr" class="mw-content-ltr"> Within the template, we use <code><nowiki>{{{reason}}}</nowiki></code> and <code><nowiki>{{{signature}}}</nowiki></code> to identify each parameter, instead of a number. To pass these parameters by name, identify each parameter when passing it: </div> <span lang="en" dir="ltr" class="mw-content-ltr"><nowiki>{{Thankyou|signature=Me|reason=being who you are}}</nowiki></span> <div lang="en" dir="ltr" class="mw-content-ltr"> In this case, template <code><nowiki>{{Thankyou}}</nowiki></code> receives parameters <code><nowiki>{{{reason}}}=being who you are</nowiki></code> and <code><nowiki>{{{signature}}}=Me</nowiki></code> and produces: </div> <div lang="en" dir="ltr" class="mw-content-ltr"> {{Thankyou|signature=Me|reason=being who you are}} </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Named parameters are '''case-sensitive''', so: </div> <div lang="en" dir="ltr" class="mw-content-ltr"> <pre><nowiki>{{Thankyou|signature=Me|Reason=being who you are|reason=being case-sensitive}}</nowiki></pre> </div> <div lang="en" dir="ltr" class="mw-content-ltr"> produces: </div> <div lang="en" dir="ltr" class="mw-content-ltr"> {{Thankyou|signature=Me|Reason=being who you are|reason=being case-sensitive}} </div> <div lang="en" dir="ltr" class="mw-content-ltr"> The advantage of using named parameters in your template, besides also being flexible in the order parameters can be passed, is that it makes the template code much easier to understand if there are many parameters. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Spaces and newlines are automatically stripped from the start and end of named parameter names and values, but are preserved in unnamed parameters. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> === Mixing named and unnamed parameters === </div> <span lang="en" dir="ltr" class="mw-content-ltr">If the template supports it, both kinds of parameters can be used in one call.</span> <span lang="en" dir="ltr" class="mw-content-ltr">The template contents would be changed to:</span> <syntaxhighlight lang="wikitext">'''A little thank you...''' for {{{reason|{{{1}}}}}}. Hugs, {{{signature|{{{2}}}}}}</syntaxhighlight> {{tmpl|0=<span lang="en" dir="ltr" class="mw-content-ltr">Then, <code><nowiki>{{</nowiki>Thankyou{{!}}$1{{!}}signature=$2<nowiki>}}</nowiki></code> results in:</span> |1=<span lang="en" dir="ltr" class="mw-content-ltr">supporting both parameter types</span> |2=<span lang="en" dir="ltr" class="mw-content-ltr">Me</span> }} {{Thankyou|supporting both parameter types|signature=<span lang="en" dir="ltr" class="mw-content-ltr">Me</span>}} <span lang="en" dir="ltr" class="mw-content-ltr">Be careful when doing this, because it can result in conterintuitive results as unnamed parameter counts are based only on the unnamed parameters, not the named parameters.</span> {{tmpl|0=<span lang="en" dir="ltr" class="mw-content-ltr">For example, <code><nowiki>{{</nowiki>Thankyou{{!}}$1{{!}}reason=$2<nowiki>}}</nowiki></code> results in:</span> |1=<span lang="en" dir="ltr" class="mw-content-ltr">Me</span> |2=<span lang="en" dir="ltr" class="mw-content-ltr">supporting both parameter types</span> }} {{Thankyou|Me|reason=<span lang="en" dir="ltr" class="mw-content-ltr">supporting both parameter types</span>}} <span lang="en" dir="ltr" class="mw-content-ltr">The template is coded to prefer the named parameter for the reason over the unnamed parameter, resulting in the "Me" being lost and no signature being given.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This results in a default value of {{{2}}} being shown, as explained below.</span> {{tmpl|0=<span lang="en" dir="ltr" class="mw-content-ltr">Similarly, <code><nowiki>{{</nowiki>Thankyou{{!}}reason=$1{{!}}$2<nowiki>}}</nowiki></code> results in:</span> |1=<span lang="en" dir="ltr" class="mw-content-ltr">supporting both parameter types</span> |2=<span lang="en" dir="ltr" class="mw-content-ltr">Me</span> }} {{Thankyou|reason=supporting both parameter types|1=<span lang="en" dir="ltr" class="mw-content-ltr">Me</span>}} <span lang="en" dir="ltr" class="mw-content-ltr">Even though "Me" is the second parameter, it is the first ''unnamed'' parameter, and so it is assigned to <nowiki>{{{1}}}</nowiki> and <nowiki>{{{2}}}</nowiki> is left unassigned.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> === Default values === </div> {{see also|Manual:Advanced templates#Use of parameter default}} <div lang="en" dir="ltr" class="mw-content-ltr"> If you transclude a template that expects parameters, but do not provide their arguments, in this way: </div> <span lang="en" dir="ltr" class="mw-content-ltr"><nowiki>{{Thankyou}}</nowiki></span> <div lang="en" dir="ltr" class="mw-content-ltr"> in the numbered parameters example above you would get the following: </div> {{Thankyou}} <div lang="en" dir="ltr" class="mw-content-ltr"> Since no arguments were passed in, the template presents the parameters themselves, instead of their respective values. In these cases, it may be useful to define ''default'' values for the parameters, i.e. values that will be used if no value is passed in. For example, if the template contents are changed to: </div> <syntaxhighlight lang=moin> '''A little thank you...''' for {{{reason|everything}}}. Hugs, {{{signature|Me}}} </syntaxhighlight> <div lang="en" dir="ltr" class="mw-content-ltr"> then <code><nowiki>{{{reason|everything}}}</nowiki></code> defines that if no argument is provided for parameter <code>{{{reason}}}</code>, then the value <code>everything</code> will be used. Similarly, <code><nowiki>{{{signature|Me}}}</nowiki></code>, defaults parameter <code>{{{signature}}}</code> to value <code>Me</code>. Now, transcluding the template again without passing any argument results in the following: </div> <!-- strictly speaking, this example is false, because the template call was changed to obtain the desired effect - but the effect is the same if the template is defined as described --> <div lang="en" dir="ltr" class="mw-content-ltr"> {{Thankyou|reason=everything|signature=Me}} </div> {{note|1=<span lang="en" dir="ltr" class="mw-content-ltr">The value of a parameter can be an empty string.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example, in <code><nowiki>{{foo|bar=}}</nowiki></code> or <code><nowiki>{{foo|bar=|baz=qux}}</nowiki></code>, the <code>foo</code> template considers the <code>bar</code> parameter to be <code>""</code>.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This is different from omitting the parameter altogether, which leaves it undefined and triggers the default value mechanism described above.</span> }} {{note|1=<span lang="en" dir="ltr" class="mw-content-ltr">If you need to treat an empty string the same way as a missing parameter, you can use a conditional operator through an extension like [[Special:MyLanguage/Extension:ParserFunctions|ParserFunctions]].</span> <span lang="en" dir="ltr" class="mw-content-ltr">For instance, <code><nowiki>{{#if:{{{1|}}}|{{{1|}}}|undefined}}</nowiki></code> returns undefined if the parameter is either undefined or empty, while <code><nowiki>{{{1|undefined}}}</nowiki></code> does so only if the parameter is undefined.</span> }} <span lang="en" dir="ltr" class="mw-content-ltr">Default values are often used to specify alternate names of parameters.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example, if you have <code><nowiki>{{{a|{{{b|}}} }}}</nowiki></code>, the template will first look for a parameter named "a".</span> <span lang="en" dir="ltr" class="mw-content-ltr">If it is not set, it will use the parameter named "b".</span> <span lang="en" dir="ltr" class="mw-content-ltr">If neither "a" nor "b" is set, it will output nothing.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> === Passing parameters to other templates === </div> <span lang="en" dir="ltr" class="mw-content-ltr">If raw parameter syntax is generated by the above template call, and then passed through to another template, it is '''not''' interpreted as a parameter.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This means that {{Tl|thankyou2}}, which just calls {{tl|thankyou}} with no parameters, does not work:</span> {{tlx|thankyou2|everything|me}} → {{thankyou2|everything|me}} <span lang="en" dir="ltr" class="mw-content-ltr">You instead need to explicitly pass the parameter to the other template, i.e if {{tl|thankyou3}} contains</span> <syntaxhighlight lang="wikitext"> {{thankyou|{{{1}}}|{{{2}}}}} </syntaxhighlight> <span lang="en" dir="ltr" class="mw-content-ltr">then works properly:</span> {{tlx|thankyou3|everything|me}} → {{thankyou3|everything|me}} <div lang="en" dir="ltr" class="mw-content-ltr"> This example does not [[#Empty vs undefined parameters|preserve emptiness vs. undefinedness in parameter values]] – you would need more complicated syntax if you wanted to do that. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> === Empty vs undefined parameters === </div> <span lang="en" dir="ltr" class="mw-content-ltr">The <code>{{red|{{((}}}}t2demo{{red|{{!!}}}} {{green|a}} {{red|{{))}}}}</code> (refer to {{tl|t2demo}} ), with a double pipe, sets the first parameter to an '''empty''' string instead of leaving it undefined.</span> <span lang="en" dir="ltr" class="mw-content-ltr">It produces the output <code>start--middle- a -end</code>, similar to how <code>{{red|{{((}}}}t2demo{{red|{{!}}}}1={{red|{{!}}}}2= {{green|a}} {{red|{{))}}}}</code> results in <code>{{t2demo|1=|2={{#tag:font| a |color="green"|style="color:green"}}}}</code>.</span> <span lang="en" dir="ltr" class="mw-content-ltr">On the other hand, explicitly setting the parameter "2" to "a," results in the first unnamed parameter being left '''undefined''':</span> <div lang="en" dir="ltr" class="mw-content-ltr"> <code>{{red|{{((}}}}t2demo{{red|{{!}}}}2= {{green|a}} {{red|{{))}}}}</code> results in {{t2demo|2={{#tag:font| a |color="green"|style="color:green"}}}} </div> <div lang="en" dir="ltr" class="mw-content-ltr"> If the second parameter should not be trimmed, it must be unnamed. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Therefore, you can assign an empty string to the first parameter, but you cannot leave it undefined. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> ==== Making emptiness and undefinedness equivalent ==== </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Good template coding practices result in passing an empty string to a parameter working the same as not assigning any value. This makes things easier and more consistent. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> For example, using <code>p=</code> can show that a template has a parameter "p" that doesn't have a value yet. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> To make an empty string and an undefined value equivalent, use the following approaches: </div> * <span lang="en" dir="ltr" class="mw-content-ltr">Use <code><nowiki>{{{p|}}}</nowiki></code> exclusively instead of <code>{{{p}}}</code> or <code>{{{p|q}}}</code> where "q" is a non-empty value.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">Use conditional checks like <code><nowiki>{{#if:{{{p|}}}|..{{{p}}}..|..}}</nowiki></code>, to ensure <code>{{{p}}}</code> is only used when it has a value.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If for some reason you want to treat undefined parameters differently from empty parameters or any other possible value you can compare the same parameter twice with different defaults, i.e <code><nowiki>{{#ifeq:{{{foo|bar}}}|{{{foo|baz}}}|parameter is defined|parameter is undefined}}</nowiki></code>.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> === Using equals signs in unnamed parameters === </div> <span lang="en" dir="ltr" class="mw-content-ltr">Unnamed parameters can include equals signs, but this must be done indirectly.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Here are some methods using [[template:T1demo]]:</span> ; <span lang="en" dir="ltr" class="mw-content-ltr">Default Value for Undefined Parameter</span> <span lang="en" dir="ltr" class="mw-content-ltr">Assign a default value to an undefined parameter:</span> <code><nowiki>{{T1demo|{{{1| a=b }}}}}</nowiki></code> <span lang="en" dir="ltr" class="mw-content-ltr">This renders as:</span> <code>{{T1demo|{{{1| a=b }}}}}</code>. ; <span lang="en" dir="ltr" class="mw-content-ltr">Using the <code><nowiki>{{=}}</nowiki></code> parser function</span> <span lang="en" dir="ltr" class="mw-content-ltr">Use a parser function that safely includes an equals sign:</span> <code><nowiki>{{T1demo| a{{=}}b }}</nowiki></code> <span lang="en" dir="ltr" class="mw-content-ltr">This renders as:</span> <code>{{T1demo| a{{=}}b }}</code>. ; <span lang="en" dir="ltr" class="mw-content-ltr">HTML Entities</span> <span lang="en" dir="ltr" class="mw-content-ltr">Replace the equals sign with an HTML entity for display:</span> <code><nowiki>{{T1demo| a&#61;b }}</nowiki></code> <span lang="en" dir="ltr" class="mw-content-ltr">This renders as:</span> <code>{{T1demo| a=b }}</code>. <div lang="en" dir="ltr" class="mw-content-ltr"> This renders correctly without affecting the other parameters. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> === Handling unmatched curly and square brackets === </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Unmatched curly brackets (<code><nowiki>{{</nowiki></code>, <code>}}</code>) or square brackets (<code><nowiki>[[</nowiki></code>, <code>]]</code>) must be inside nowiki tags or use HTML entities: </div> * <span lang="en" dir="ltr" class="mw-content-ltr">Rendering curly brackets have two options:</span> ** <span lang="en" dir="ltr" class="mw-content-ltr">Use <code><nowiki><nowiki>{{</nowiki></nowiki></code> or <code>&#123;</code> for <code>{</code></span> ** <span lang="en" dir="ltr" class="mw-content-ltr">Use <code><nowiki><nowiki>}}</nowiki></nowiki></code> or <code>&#125;</code> for <code>}</code>.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">Use <code>&#91;</code> for <code>[</code> and <code>&#93;</code> for <code>]</code>.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> Below are some examples: </div> ; <span lang="en" dir="ltr" class="mw-content-ltr">Unmatched curly brackets</span> <code><nowiki>{{T1demo| <nowiki>{{</nowiki>content<nowiki>}}</nowiki> }}</nowiki></code> <span lang="en" dir="ltr" class="mw-content-ltr">This correctly renders the braces without breaking the template.</span> ; <span lang="en" dir="ltr" class="mw-content-ltr">Unmatched square brackets</span> <code><nowiki>{{T1demo| text [link] more text }}</nowiki></code> <span lang="en" dir="ltr" class="mw-content-ltr">This correctly renders the braces without breaking the template.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This renders as:</span> <code>{{T1demo| text [link] more text }}</code> <div lang="en" dir="ltr" class="mw-content-ltr"> Unmatched pairs not placed in nowiki tags either prevent template expansion or are taken as closing braces for the template call. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Below are some examples: </div> <code><nowiki>{{T1demo|abc]]def[[ghi}}</nowiki></code> <div lang="en" dir="ltr" class="mw-content-ltr"> This will not expand correctly because of unmatched brackets. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> The correct use: </div> <code><nowiki>{{T1demo|abc<nowiki>]]</nowiki>def<nowiki>[[</nowiki>ghi}}</nowiki></code> <span lang="en" dir="ltr" class="mw-content-ltr">This renders as:</span> <code>{{T1demo|abc<nowiki>]]</nowiki>def<nowiki>[[</nowiki>ghi}}</code> <div lang="en" dir="ltr" class="mw-content-ltr"> ==== Template-generated brackets ==== </div> <span lang="en" dir="ltr" class="mw-content-ltr">An alternate technique for passing arguments with unmatched brackets is to wrap them in another template.</span> <span lang="en" dir="ltr" class="mw-content-ltr">In that situation, (which exists with {{tl|((}} and {{tl|))}}) on this wiki), the unmatched brackets will be rendered literally, and not decoded as another template call.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example:</span> <syntaxhighlight lang="wikitext"> {{t1demo|{{((}}t1demo{{))}}}} </syntaxhighlight> <span lang="en" dir="ltr" class="mw-content-ltr">results in:</span> {{t1demo|{{((}}t1demo{{))}}}} <span lang="en" dir="ltr" class="mw-content-ltr">When [[Special:MyLanguage/Help:Substitution|substituting]] a template, template inclusions are parsed once when the subst happens (with the same caveats explained above) and then a second time when rendering the resulting wikitext.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example:</span> <syntaxhighlight lang="wikitext"> {{subst:((}}t1demo|foo}} </syntaxhighlight> <span lang="en" dir="ltr" class="mw-content-ltr">will expand on save to:</span> <syntaxhighlight lang="wikitext"> {{t1demo|foo}} </syntaxhighlight> <span lang="en" dir="ltr" class="mw-content-ltr">which will then render as:</span> {{t1demo|foo}} <span lang="en" dir="ltr" class="mw-content-ltr">If the wikitext generated via the first subst itself includes "subst:" syntax it will not be processed on the same save, but may be on the next save.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This technique may be used to implement [[Special:MyLanguage/Manual:Recursive conversion of wikitext|recursive substitutions]] that take multiple saves to evaluate.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> === Using pipes in parameter values === </div> <span lang="en" dir="ltr" class="mw-content-ltr">A parameter value cannot contain a pipe character (|), because it would be interpreted as the end of that parameter and the start of the next parameter.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This can be worked around by using the {{ll|Help:Parser function|parser function}} <code><nowiki>{{!}}</nowiki></code>, or the HTML entity &124;.</span> <span lang="en" dir="ltr" class="mw-content-ltr">The two methods of doing this have slightly different behavior, which can be relevant in some corner cases like when a template is producing [[Special:MyLanguage/Help:Tables|wikitable]] syntax.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Example:</span> <code><nowiki>{{T1demo|abc|def}}</nowiki></code> <span lang="en" dir="ltr" class="mw-content-ltr">produces:</span> {{T1demo|abc|def}} <span lang="en" dir="ltr" class="mw-content-ltr">The "def" doesn't display because it is treated as part of another unnamed parameter, which the template does not use.</span> <code><nowiki>{{T1demo|abc{{!}}def}}</nowiki></code> <span lang="en" dir="ltr" class="mw-content-ltr">produces:</span> {{T1demo|abc{{!}}def}} <span lang="en" dir="ltr" class="mw-content-ltr">The "def" displays properly.</span> <code><nowiki>{{T1demo|abc&#124;def}}</nowiki></code> <span lang="en" dir="ltr" class="mw-content-ltr">produces:</span> {{T1demo|abc|def}} <div lang="en" dir="ltr" class="mw-content-ltr"> The "def" displays properly again. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> === Formatting template calls using extra parameters === </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Since templates ignore parameters they are passed but do not handle specifically, they can be used as a way of a adding extra whitespace or unused content to the template call. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> For example: </div> <syntaxhighlight lang="wikitext"> {{template name|foo|bar|baz|mumble|quux}} </syntaxhighlight> <span lang="en" dir="ltr" class="mw-content-ltr">is equivalent to, assuming the template doesn't recognize SPACEN as a parameter name:</span> <syntaxhighlight lang="wikitext"> {{template name|SPACE1= |foo|SPACE2= |bar|SPACE3=Random stuff |baz|SPACE4= |mumble|SPACE5= quux }} </syntaxhighlight> <div lang="en" dir="ltr" class="mw-content-ltr"> It is also possible to use the same name for each spacer (often the empty string), but this will populate [[:Category:Pages using duplicate arguments in template calls]], which many wikis prefer to keep empty to catch instances of user error. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> This can be used to make the template render in a way similar to its output, like showing each row of [[w:Template:Chess position]] on its own like to make the wikitext also look like a chessboard. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> == Tracking parameter usage == </div> {{see also|Help:Tracking categories}} <div lang="en" dir="ltr" class="mw-content-ltr"> It may be wise for a template to add a link or category to a page if a certain parameter or combination of parameters is used, to make if possible to easily determine what pages are using a given parameter, and thus what the impacts of changing that parameter in the template would be. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> == Evaluation process == </div> {{Note|1=<span lang="en" dir="ltr" class="mw-content-ltr">This is an advanced topic which you can skip unless you need it.</span>}} <span lang="en" dir="ltr" class="mw-content-ltr">Generally speaking, template parameters are substituted into the template after tokenization, but as is.</span> <span lang="en" dir="ltr" class="mw-content-ltr">They are not evaluated until they are used.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This has a few consequences:</span> # <span lang="en" dir="ltr" class="mw-content-ltr">If you have a <code>Template:Start</code> containing <code><nowiki>{{mytemplate</nowiki></code>, and a <code>Template:End</code> containing <code><nowiki>|foo=bar}}</nowiki></code>, and put <code><nowiki>{{start}}{{end}}</nowiki></code> on a page, ''mytemplate'' isn't transcluded, because tokens like "|" cannot be added by a template and keep their special meaning in templates.</span> <span lang="en" dir="ltr" class="mw-content-ltr">You can still use templates to control the name of a parameter or template, but you cannot split a template call amongst multiple templates.</span> # '''<span lang="en" dir="ltr" class="mw-content-ltr">Dead-code elimination:</span>''' <span lang="en" dir="ltr" class="mw-content-ltr">If you make a template call like <code><nowiki>{{foo|{{DISPLAYTITLE:Bar}} }}</nowiki></code>, and <code>Template:Foo</code> does not contain <nowiki>{{{1}}}</nowiki>, then the <code>DISPLAYTITLE</code> is not used, since it is only evaluated when needed, and there is no parameter to substitute it into, so it is never evaluated.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This usually comes into play when using {{ll|Extension:ParserFunctions}}, and can be especially noticed when used in combination with the <code><nowiki>int:</nowiki></code> magic word that varies by user language.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This isn't perfect, and in some cases even if the result of expanding a template is not used (because it is part of an if statement condition, for example), the process of evaluating it can still have [[w:Side effect (computer science)|side effects]].</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example, any {{ll|Help:Links|links}} produced or other templates used will still be added to [[Special:WhatLinksHere]] even if they are not displayed.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Template parameters are [[w:pass by value|pass by value]], which means a template cannot modify its arguments.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Parameters are treated as [[w:Associative array|associative array]], and parameter names are evaluated before parameter values.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If the same parameter name is given more than once (either as named or unnamed), only the last instace is used, and the page is added to [[:Category:Pages using duplicate arguments in template calls]].</span> <span lang="en" dir="ltr" class="mw-content-ltr">Template calls starting with the magic word <code>subst:</code> or <code>safesubst:</code> are evaluated in a separate first pass that only happens at save time, along with <nowiki>~~~~</nowiki> and links using the [[Special:MyLanguage/pipe trick|pipe trick]].</span> <span lang="en" dir="ltr" class="mw-content-ltr">If they cannot be evaluated during the first pass, <code>subst:</code> calls are ignored, and <code>safesubst:</code> are treated as if a normal template.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Many but not all parser functions, parser tags and trancluded special pages are not directly included like templates but instead are replaced by a "strip marker".</span> <span lang="en" dir="ltr" class="mw-content-ltr">This means you cannot manipulate the results with parser functions like padleft: or similar functions from extensions, as they see the strip marker instead of the result of the parser function.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> === Recursion in templates === </div> <span lang="en" dir="ltr" class="mw-content-ltr">Including a template in itself won't throw MediaWiki into infinite recursion.</span> <span lang="en" dir="ltr" class="mw-content-ltr">MediaWiki will stop the recursion with the template's name in bold.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example, if the content of Template:Aaaa is <code>a <nowiki>{{Aaaa}}</nowiki> z</code>, it'll display "a a <span class="error">Template loop detected: '''Template:Aaaa'''</span> z z".</span> <span lang="en" dir="ltr" class="mw-content-ltr">This safeguard precludes a potentially useful template idiom where a template self-normalizes its own calling arguments.</span> <span lang="en" dir="ltr" class="mw-content-ltr">In this forbidden example <code>template:d</code> can either be called <code><nowiki>{{d|20200311}}</nowiki></code> or <code><nowiki>{{d|y=2020|m=3|d=11}}</nowiki></code>.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If called in the first manner, it recurses into itself with the second argument structure (obtained using string parser functions), which then follows a unified processing path.</span> <syntaxhighlight lang="wikitext"> {{#if:{{{1|}}}|{{d|y={{#sub:{{{1}}}|0|4}}|m={{#sub:{{{1}}}|4|2}}|d={{#sub:{{{1}}}|6|2}}}}|<!-- processing path with arguments y,m,d regardless of original call pattern -->}} </syntaxhighlight> <span lang="en" dir="ltr" class="mw-content-ltr">If <code>template:d</code> is modified to recurse into <code>template:d/2</code> and <code>template:d/2</code> is an ''identical manual copy'' of <code>template:d</code> this idiom works fine as the self-recursion safeguard operates dynamically and not statically.</span> <span lang="en" dir="ltr" class="mw-content-ltr">A feasible way for the MediaWiki software to loosen the self-recursion rule would be to require that each recursive call have a distinct argument count from all previous active calls, at most once recursing with the argument count non-decreasing.</span> <span lang="en" dir="ltr" class="mw-content-ltr">That would provide a strong guarantee against infinite self-recursion while enabling useful idioms such as the one described here in a flexible manner.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If the processing path is of low complexity, a simple solution using only one template is to handle each calling convention on a separate if/else branch, duplicating the logic of the processing path within each case.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If the processing path is more complex, each call-structure case can delegate to an implementation template with a unified call structure which provides the final template behaviour.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> === Tables in parameters === </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Since the pipe character (<code>|</code>) and equality sign (<code>=</code>) have different meanings in template calls and wikitables, in order to use table markup in the value of a template parameter one generally needs to "escape" those characters (i.e., protect them from interpretation as template markup) using special sequences: </div> * <span lang="en" dir="ltr" class="mw-content-ltr">the built-in {{ll|Help:Magic words|magic word}} <code><nowiki>{{!}}</nowiki></code> provides an "escaped" version of <code>|</code> since MediaWiki 1.24</span> * <span lang="en" dir="ltr" class="mw-content-ltr">the built-in magic word <code><nowiki>{{=}}</nowiki></code> provides an "escaped" version of <code>=</code> since MediaWiki 1.39</span> <span lang="en" dir="ltr" class="mw-content-ltr">Before the introduction of these magic words, many wikis used templates to accomplish the same things.</span> <span lang="en" dir="ltr" class="mw-content-ltr">On such a wiki, the magic words take precendence over the same-named templates.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> ====Example table==== </div> {| class=wikitable !A!!B!!C |- |A1||B1||C1 |- |A2||B2||C1 |} '''<span lang="en" dir="ltr" class="mw-content-ltr">Table code:</span>''' <syntaxhighlight lang=wikitext> {| class=wikitable !A!!B!!C |- |A1||B1||C1 |- |A2||B2||C1 |} </syntaxhighlight> '''<span lang="en" dir="ltr" class="mw-content-ltr">Escaped table code:</span>''' <syntaxhighlight lang=wikitext> {{{!}} class{{=}}wikitable !A!!B!!C {{!}}- {{!}}A1{{!}}{{!}}B1{{!}}{{!}}C1 {{!}}- {{!}}A2{{!}}{{!}}B2{{!}}{{!}}C2 {{!}}} </syntaxhighlight> <span lang="en" dir="ltr" class="mw-content-ltr">Note that the first left-brace (<code>{</code>) is interpreted as a literal left-brace character because it is immediately followed by the <code><nowiki>{{!}}</nowiki></code> magic word.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Similarly, the last right-brace (<code>}</code>) is interpreted as a literal right-brace character because it is immediately preceeded by the same magic word.</span> <span lang="en" dir="ltr" class="mw-content-ltr">However, in some cases these brace characters do cause problems, so some wikis provide templates for escaping these characters, as well:</span> * <span lang="en" dir="ltr" class="mw-content-ltr">the template call <code><nowiki>{{(}}</nowiki></code> might provide an "escaped" version of <code>{</code></span> * <span lang="en" dir="ltr" class="mw-content-ltr">the template call <code><nowiki>{{)}}</nowiki></code> might provide an "escaped" version of <code>}</code></span> <span lang="en" dir="ltr" class="mw-content-ltr">Some wikis go even further and provide other convenience templates like {{Template|(!}} (<code><nowiki>{|</nowiki></code>), {{Template|!)}} (<code>|}</code>), {{Template|!!}} (<code>||</code>).</span> <span lang="en" dir="ltr" class="mw-content-ltr">On such a wiki, the code can be simplified a bit to this form:</span> <syntaxhighlight lang=wikitext> {{(!}} class{{=}}wikitable !A!!B!!C {{!}}- {{!}}A1{{!!}}B1{{!!}}C1 {{!}}- {{!}}A2{{!!}}B2{{!!}}C2 {{!)}} </syntaxhighlight> <div lang="en" dir="ltr" class="mw-content-ltr"> == Controlling template inclusion == </div> <span lang="en" dir="ltr" class="mw-content-ltr">By default, a template's content is displayed in its entirety, both when viewed directly and when included in another page.</span> <span lang="en" dir="ltr" class="mw-content-ltr">The template's page when viewed directly appears exactly as the template would render without any parameters.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If the template requires parameters to function properly, this will result in raw wikitext syntax or errors as a result of them being missing.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example:</span> * <span lang="en" dir="ltr" class="mw-content-ltr">If a parameter has no default value, it shows as the literal text <nowiki>{{{1}}}</nowiki>, indicating the template needs a parameter.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">If a parameter has an empty default value (it is written as <nowiki>{{{1|}}}</nowiki>), it displays nothing, which achieves the intended effect but lacks clarity for self-documentation.</span> {{tmpl|0=<span lang="en" dir="ltr" class="mw-content-ltr">Using a non-empty default value like <code><nowiki>{{{1|</nowiki>$1<nowiki>}}}</nowiki></code> could clarify a parameter's role, especially for templates involving images.</span> |1=<span lang="en" dir="ltr" class="mw-content-ltr">image</span> }} * <span lang="en" dir="ltr" class="mw-content-ltr">If a parameter without a default is passed to the <code>#expr</code> parser function, it results in an error message: "Expression error: unrecognized punctuation character '{'."</span> * <span lang="en" dir="ltr" class="mw-content-ltr">If a template creates a table, it's helpful for the template page to show the table's structure rather than the wikitext used to make it.</span> <span lang="en" dir="ltr" class="mw-content-ltr">To do this, the table syntax isn't enclosed in tags, and each table element includes both {{tag|noinclude}} and {{tag|includeonly}} parts where needed.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> However, you can control which parts of a template will be seen and included by the use of the {{tag|noinclude|open}}, {{tag|includeonly|open}} and {{tag|onlyinclude|open}} tags. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Anything between {{tag|noinclude|open}} and {{tag|noinclude|close}} will be seen only when the template's page is being viewed directly, but not when it is included in another page. This is useful when you want to include text or code in a template that you do not want to propagate to any pages which include it, such as: </div> <div lang="en" dir="ltr" class="mw-content-ltr"> * [[Special:MyLanguage/Help:Categories|Category]] links when categorizing the template itself </div> <div lang="en" dir="ltr" class="mw-content-ltr"> * [[Special:MyLanguage/Help:Links#Interlanguage links|interlanguage links]] to similar templates in other languages </div> <div lang="en" dir="ltr" class="mw-content-ltr"> * Explanatory text about how to use the template. </div> <span lang="en" dir="ltr" class="mw-content-ltr">It's a common pattern on some wikis to use a template like {{tl|documentation}} to transclude the documentation from a subpage of the template.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example, [[Template:Void]] is documented at [[Template:Void/doc]].</span> <div lang="en" dir="ltr" class="mw-content-ltr"> Likewise, anything between {{tag|includeonly|open}} and {{tag|includeonly|close}} will be processed and displayed only when the page is being included, but not when the template page is being viewed directly, and is useful in situations such as: </div> <div lang="en" dir="ltr" class="mw-content-ltr"> * [[Special:MyLanguage/Help:Categories|Categorizing]] pages which include the template. </div> <span lang="en" dir="ltr" class="mw-content-ltr">'''Note:''' when changing the categories applied by a template in this fashion, the categorization of the pages which include that template may not be updated until some time later: this is handled by the {{ll|Manual:Job queue|job queue}}.</span> <span lang="en" dir="ltr" class="mw-content-ltr">To force the re-categorization of a particular page, open that page for editing and save it without changes.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> * Ensuring that the template's code is not executed when viewing the template page itself. Typically this is because it expects parameters, and its execution without parameters has an undesired result. </div> <span lang="en" dir="ltr" class="mw-content-ltr">Everything outside {{tag|noinclude|open}} and {{tag|includeonly|open}} is processed and displayed normally; that is, both when the template page is being viewed directly and when the template is included in another page.</span> <span lang="en" dir="ltr" class="mw-content-ltr">The focus is on what is inside these two tags.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Everything outside {{tag|onlyinclude|open}} tags is discarded in the transclusion.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Even sections tagged includeonly are discarded in the transclusion unless they are also tagged as onlyinclude.</span> <span lang="en" dir="ltr" class="mw-content-ltr">The focus is only on what is inside this tag.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example, if a page like [[Special:MyLanguage/Help:Templates/onlyinclude demo|Help:Templates/onlyinclude demo]] has the wikitext:</span> <syntaxhighlight lang="wikitext"> abc<onlyinclude>def</onlyinclude>ghi<includeonly>jkl</includeonly> </syntaxhighlight> <div lang="en" dir="ltr" class="mw-content-ltr"> The result of transcluding it is {{Help:Templates/onlyinclude demo}}. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Nesting of these tags is also possible. </div> <span lang="en" dir="ltr" class="mw-content-ltr">The three partial transclusion tags enable all possible combinations of what is processed and rendered.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Comments also fill a role.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Inclusion tags are respected when using <code><nowiki>{{subst:templatename}}</nowiki></code>, but they are '''not''' respected when using <code><nowiki>{{msgnw:templatename}}</nowiki></code> as that displays the raw wikitext without any processing.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> == Section transclusion == </div> <div lang="en" dir="ltr" class="mw-content-ltr"> To transclude different sections of a template on different pages, you can wrap the content in onlyinclude tags and use an if statement on parameters to select which section. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Consider "Template:Example" with this wikitext: </div> <syntaxhighlight lang="wikitext"> == Section 1 == {{#ifeq:{{{1|1}}}|1| Content of section one. }} {{#ifeq:{{{1|2}}}|2| == Section 2 == Content of section two. }} </syntaxhighlight> <div lang="en" dir="ltr" class="mw-content-ltr"> This will render both sections on the example page itself, and allow other pages to transclude the first section with <code><nowiki>{{example|1}}</nowiki></code> and the second section with <code><nowiki>{{example|2}}</nowiki></code>. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Another approach is to use literal parameter syntax instead: </div> <syntaxhighlight lang="wikitext"> {{{section1| == Section 1 == Content of section one. }}} {{{section2| == Section 2 == Content of section two. }}} </syntaxhighlight> <span lang="en" dir="ltr" class="mw-content-ltr">Transclude the first section with <code><nowiki>{{example|section2=}}</nowiki></code> and the second section with <code><nowiki>{{example|section1=}}</nowiki></code>.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If neither parameter is used, then both sections will display.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> A third approach is to use {{ll|Extension:Labeled Section Transclusion|Labeled Section Transclusion}}. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> == Organizing templates == </div> <div lang="en" dir="ltr" class="mw-content-ltr"> For templates to be effective, users need to find them, and find out how to use them. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> To find them, users can: </div> # <span lang="en" dir="ltr" class="mw-content-ltr">Click <code>{{int|specialpages}}</code> > <code>{{int|allpages}}</code></span> # <span lang="en" dir="ltr" class="mw-content-ltr">In the <code>{{int|namespace}}</code> list, choose '''Template''' and click <code>{{int|allpagessubmit}}</code>.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> To give usage information, include an example like this one on the template page: </div> <div lang="en" dir="ltr" class="mw-content-ltr"> <pre><nowiki> <noinclude> == Usage == Welcome users: {{Thankyou|reason=your reason|signature=your signature}} </noinclude> </nowiki></pre> </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Then, an editor can simply copy and paste the example to use the template. </div> <span lang="en" dir="ltr" class="mw-content-ltr">While editing a page, a list of all templates used is available under the editing form, in a collapsible section titled <code>{{int|templatesused}}</code> (also named <code>{{int|templatesusedpreview}}</code>, or <code>{{int|templatesusedsection}}</code> depending on the context).</span> <span lang="en" dir="ltr" class="mw-content-ltr">This list provides a convenient link to the template's page, as well as information about its protection status.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Redirected templates are shown in italics, with the redirect target added as a separate list item.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> == Linking to a template == </div> <div lang="en" dir="ltr" class="mw-content-ltr"> A template page can be linked to like any other wiki page. For example, the link [[Template:Navbar]] is generated using the wikicode <code><nowiki>[[Template:Navbar]]</nowiki></code>. </div> <span lang="en" dir="ltr" class="mw-content-ltr">On many wikis, [[Template:Tl]] can be used to provide a link to a template formatted in a way that shows the "double curly-braces" wikicode necessary to transclude the template without actually doing the tranclusion.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example, the code <code><nowiki>{{tl|Navbar}}</nowiki></code> may be used to create the link {{tl|Navbar}}.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This construct is commonly used when referring to templates in template documentation, on help pages, and on talk pages.</span> <span lang="en" dir="ltr" class="mw-content-ltr">The same effect can be achieved by using <code><nowiki>{{[[Template:Navbar|Navbar]]}}</nowiki></code>, but the <code>{{tl|tl}}</code> approach involves much less typing.</span> <span lang="en" dir="ltr" class="mw-content-ltr">On any given wiki the Tl template, if it exists, may or may not render the text in a "code" element or as monospace type.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If not (as on this wiki), another similarly named template may do so.</span> <span lang="en" dir="ltr" class="mw-content-ltr">See, for example, the [[Template:Tl#See also|"See also" section of our Template:Tl documentation]].</span> <div lang="en" dir="ltr" class="mw-content-ltr"> == Template naming == </div> <div lang="en" dir="ltr" class="mw-content-ltr"> The name of a template is case-sensitive excluding the first character. </div> <span lang="en" dir="ltr" class="mw-content-ltr">You make [[Special:MyLanguage/Help:Redirect|redirects]] for alternate capitalizations.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example, if a template is named "AdminAbbr", you can create a redirect named "Adminabbr".</span> <span lang="en" dir="ltr" class="mw-content-ltr">This way, the template can be called with either <code><nowiki>{{AdminAbbr}}</nowiki></code> or <code><nowiki>{{adminabbr}}</nowiki></code>.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If an editor prefers a mix of upper and lower case for clarity, they can use functions like [[Special:MyLanguage/Help:Parser_function#LC|lc]] or [[Special:MyLanguage/Help:Parser_function#UC|uc]].</span> <span lang="en" dir="ltr" class="mw-content-ltr">For instance, instead of <code><nowiki>{{CURRENTINTERNETTIME}}</nowiki></code>, they could use <code><nowiki>{{ {{uc:CurrentInternetTime}} }}</nowiki></code></span> <div lang="en" dir="ltr" class="mw-content-ltr"> Because template names are interpreted in the same way to the names of other pages, underscores are replaced with spaces, and any text after a number sign (what would be a [[Special:MyLanguage/Help:Links#Anchors|anchor]] in a standard link) is ignored. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> An underscore <code>_</code> can be alternative to a blank space. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> == Possible uses of templates == </div> <span lang="en" dir="ltr" class="mw-content-ltr">Templates can be used for any situation in which one wants two or more pages to contain identical or similar content that is edited together rather than independently.</span> <span lang="en" dir="ltr" class="mw-content-ltr">They can be used to:</span> * <span lang="en" dir="ltr" class="mw-content-ltr">Provide structured elements on many pages, like [[w:WP:Infoboxes|infoboxes]], [[w:WP:Template index|maintenance templates]], [[w:Template:navbox|navigational boxes]], etc.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">Perform calculations used as a programming tool on various pages, like [[w:Template:Sum]].</span> * {{anchor|Composite pages}} <span lang="en" dir="ltr" class="mw-content-ltr">Build composite pages that display the content of multiple existing pages together, like [[w:WP:Village pump (all)]] which includes content from each section of the village pump.</span> <span lang="en" dir="ltr" class="mw-content-ltr">The content of these pages can either be shown individually, or together, but the revision history, watchlist, etc. will only pick up changes to the transcluded pages and the raw wikitext of the composite page itself, not implicit changes to the composite page.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">Share some content between a few related pages.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example, the list at [[Special:MyLanguage/Help:Preferences#Beta features|Help:Preferences#Beta features]] is duplicated at [[Special:MyLanguage/Beta Features#Current Beta Features|Beta Features#Current Beta Features]].</span> <span lang="en" dir="ltr" class="mw-content-ltr">While on MediaWiki.org that is built using {{ll|Extension:LabeledSectionTransclusion}} instead, it could have been done using a template.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">Store content referenced multiple times on the same page, so it only has to be written and calculated once.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example [[w:Template:Cite Monumentenregister/URL]] is called twice by [[w:Template:Cite Monumentenregister]] in two different places, and using another template means the URL pattern only has to be written once in the base template.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">Use templates as a programming element to generate a loop: if Template:A calls Template:B 10 times with different parameters, then that crudely simulates a for loop.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If Template:B calls Template:C 10 times, then you have a nested loop of 100 calls of Template:C.</span> <span lang="en" dir="ltr" class="mw-content-ltr">But keep in mind that it is easy to run into the [[Special:MyLanguage/Manual:Template limits|template limits]] when using templates as advanced programming constructs, and using {{ll|Extension:Scribunto|Scribunto}} is generally clearer and easier to follow.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> == Copying from one wiki to another == </div> <span lang="en" dir="ltr" class="mw-content-ltr">It is possible, if {{ll|Manual:$wgEnableScaryTranscluding|allowed by the wiki configuration}} to transclude templates from other wikis.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This configuration setting is disabled on Wikimedia wikis.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Otherwise, you need to manually copy the template and its dependencies from the source wiki to the destination wiki to use it.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Templates often require [[Special:MyLanguage/Manual:Interface/Stylesheets|CSS]] or other templates, so users frequently have trouble copying templates from one wiki to another.</span> <span lang="en" dir="ltr" class="mw-content-ltr">The steps below should work for most templates.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> === MediaWiki code === </div> <div lang="en" dir="ltr" class="mw-content-ltr"> If you have import rights (specifically <code>importupload</code>) on the new wiki: </div> # <span lang="en" dir="ltr" class="mw-content-ltr">Go to [[Special:Export]] on the original wiki, and download an .xml file with the complete history of all necessary templates, as follows:</span> #* <span lang="en" dir="ltr" class="mw-content-ltr">Enter the name of the template in the big text box, e.g. "Template:Welcome". Pay special attention to capitalization and special characters – if the template name isn't exactly correct, the export may still occur but the .xml file will not have the expected data.</span> #* <span lang="en" dir="ltr" class="mw-content-ltr">Select the box <code>{{int|export-templates}}</code>.</span> #* <span lang="en" dir="ltr" class="mw-content-ltr">Select the box <code>{{int|exportcuronly}}</code>.</span> #* <span lang="en" dir="ltr" class="mw-content-ltr">Click <code>{{int|export-submit}}</code>.</span> # <span lang="en" dir="ltr" class="mw-content-ltr">Go to [[Special:Import]] on the new wiki and upload the .xml file.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> If you don't have import rights on the new wiki: </div> # <span lang="en" dir="ltr" class="mw-content-ltr">Go to the template you want to copy from the original wiki. Go to the edit page, and copy all the wikitext</span> # <span lang="en" dir="ltr" class="mw-content-ltr">On the new wiki, go to the page with the same name as the template you copied. Hit create/edit and paste the wikitext you copied. In the edit summary of each template, link to the original page for attribution.</span> # <span lang="en" dir="ltr" class="mw-content-ltr">Back in the original wiki at the edit window, below the edit box, look at the list of <code>{{int|templatesused}}</code>.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For each template listed follow these instructions.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Also do that for any template used by any of these templates, and so on.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This will copy the entire code necessary, and will suffice for some templates.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Note that only page elements parsed in rendering the page get exported, consequently documentation subpages are not exported as part of this process.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If it doesn't work also check for red links listed under <code>{{int|templatesused}}</code>, below the edit box.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If there are any repeat the above steps for these as well and also copy the code in the modules.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> After successfully importing the template and all its linked templates from the other wiki, edit it to change customisations to suit your wiki. For example to change a logo, remove redundant categories or red links. </div> <div lang="en" dir="ltr" class="mw-content-ltr"> === Extensions === </div> <span lang="en" dir="ltr" class="mw-content-ltr">An extension often used in templates is ParserFunctions.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Visit page {{ll|Help:Extension:ParserFunctions|nsp=0}} and check if any of the functions listed there are used in the templates you've copied.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If so, you have to install the {{ll|Extension:ParserFunctions|nsp=0}} extension.</span> <span lang="en" dir="ltr" class="mw-content-ltr">To install it, you'll need system admin access to the server of your MediaWiki installation.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Another dependency that may be used in templates, especially those on Wikipedia, is [[w:Lua (programming language)|Lua]]. Having <code><nowiki>{{#invoke: }}</nowiki></code> in template code is a good sign for it.</span> <span lang="en" dir="ltr" class="mw-content-ltr">In case it's used, you need to install the {{ll|Extension:Scribunto|nsp=0}} extension and system admin access is required too.</span> <span lang="en" dir="ltr" class="mw-content-ltr">See that page for more instructions about installing and using the extension.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> === CSS and JavaScript code === </div> <div lang="en" dir="ltr" class="mw-content-ltr"> Besides MediaWiki code, many templates make use of CSS and some rely on JavaScript to work fully. If the copied templates are not behaving as expected, this may be the cause. To copy the required CSS and JavaScript to your wiki you'll normally need to have admin privileges, because you'll be editing system messages in the "MediaWiki:" namespace. </div> # <span lang="en" dir="ltr" class="mw-content-ltr">Look for the use of CSS classes (text like <code>class="foobar"</code>) in the template text.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If those classes appear in <code>MediaWiki:Common.css</code> or <code>MediaWiki:Vector.css</code> on the original wiki, copy those classes to <code>MediaWiki:Common.css</code> on the new wiki and check if the template is now fine.</span> # <span lang="en" dir="ltr" class="mw-content-ltr">If the copied template is still not working as expected, check if there is code in <code>MediaWiki:Common.js</code> or <code>MediaWiki:Vector.js</code> on the original wiki.</span> <span lang="en" dir="ltr" class="mw-content-ltr">If so, you can try copying it to <code>MediaWiki:Common.js</code> on the new wiki.</span> <span lang="en" dir="ltr" class="mw-content-ltr">Normally, it is a good idea to only copy code from trusted sources, and browse the code to identify and select the relevant parts.</span> <span lang="en" dir="ltr" class="mw-content-ltr">You may find comments that can serve as clues to identify the functionality of each part.</span> <div lang="en" dir="ltr" class="mw-content-ltr"> == Redirection == </div> <span lang="en" dir="ltr" class="mw-content-ltr">If a page uses a [[Special:MyLanguage/Help:Redirect|redirect]] as a template, the redirect is resolved before processing the template and the target is used instead.</span> <span lang="en" dir="ltr" class="mw-content-ltr">This won't work if the target doesn't exist (a broken redirect), or is itself a redirect (a double redirect).</span> <span lang="en" dir="ltr" class="mw-content-ltr">A page that just includes another page as a template might look like a redirect, but there are several differences between them:</span> * <span lang="en" dir="ltr" class="mw-content-ltr">The header of the result displays the title of the page it came from.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">No "Redirected from" message is shown.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">Buttons like edit, watch, talk, history, "what links here," and "last modified" point to the referring page.</span> <span lang="en" dir="ltr" class="mw-content-ltr">To access the target page, use a section edit link and navigate from there.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">Unless '''includeonly''' and/or '''noinclude tags''' are used, the referring page shares the same categories as the target page.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">"Double redirects" work when one or both are this type of pseudo-redirect.</span> {{Note|type=reminder|text=<span lang="en" dir="ltr" class="mw-content-ltr">Embedding works on pages that support [[Special:MyLanguage/Help:Redirects|redirects]] and doesn't work on pages without it.</span>}} <div lang="en" dir="ltr" class="mw-content-ltr"> == Parser functions == </div> {{main|Help:Parser functions}} {{see also|Manual:Template limits#Expensive parser function calls}} <span lang="en" dir="ltr" class="mw-content-ltr">MediaWiki also supports [[Special:MyLanguage/Help:Parser functions|parser functions]], which function similarly to templates but follow slightly different syntax:</span> * <span lang="en" dir="ltr" class="mw-content-ltr">Parser functions utilize a ":" instead of the initial "|".</span> * <span lang="en" dir="ltr" class="mw-content-ltr">An edit page does not display parser functions used on that page.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">There is no "What links here" feature for parser functions to identify the pages where they are utilized.</span> * <span lang="en" dir="ltr" class="mw-content-ltr">Parser functions templates do not generally accept named parameters, so equal signs generally have no special significance.</span> <span lang="en" dir="ltr" class="mw-content-ltr">For example:</span> : <code><nowiki>{{ #if: not blank | x=abc }}</nowiki></code> gives <code>x=abc</code> <div lang="en" dir="ltr" class="mw-content-ltr"> == See also == </div> <div lang="en" dir="ltr" class="mw-content-ltr"> === General template usage === </div> * {{ll|Manual:Expr parser function syntax}} * [[Help:Substitution]] * [[w:Help:Template|w:Help:Template]] * {{ll|Manual:Advanced templates}} – <span lang="en" dir="ltr" class="mw-content-ltr">describes even more advanced techniques such as dynamic template calls and variable parameter names</span> * {{ll|Help:Multiple-instance templates}} – <span lang="en" dir="ltr" class="mw-content-ltr">on the use of multiple instances of the same template on a page.</span> * {{ll|Manual:Newlines and spaces#Automatic newline}} <div lang="en" dir="ltr" class="mw-content-ltr"> === Special constructs used in templates === </div> * {{ll|Help:Magic words}} – <span lang="en" dir="ltr" class="mw-content-ltr">fancy stuff you may find in some templates</span> * {{ll|Help:Extension:ParserFunctions}} – <span lang="en" dir="ltr" class="mw-content-ltr">additional fancy control functions such as #if and #switch</span> * {{ll|Help:Parser functions in templates}} – <span lang="en" dir="ltr" class="mw-content-ltr">guidance on using parser functions in templates</span> * {{ll|Help:TemplateData}} * {{ll|Help:Extension:ParserFunctions}} * {{ll|Extension:Scribunto}} <div lang="en" dir="ltr" class="mw-content-ltr"> === Other relevant information === </div> * {{ll|Help:ExpandTemplates}} * {{ll|Help:External searches}} – <span lang="en" dir="ltr" class="mw-content-ltr">a template special use case example</span> * {{ll|Manual:Importing Wikipedia infoboxes tutorial}} * {{ll|Extension:PageTemplates}} * {{ll|Manual:Creating pages with preloaded text}} – <span lang="en" dir="ltr" class="mw-content-ltr">Using templates as the starting text of a page</span> * {{ll|Help:Transclusion}} – <span lang="en" dir="ltr" class="mw-content-ltr">embedding pages from [[Special:MyLanguage/Help:Namespaces|namespaces]] other than <code>Template:</code></span> * {{ll|Manual:Template limits}} * {{ll|Help:What links here}} * [[Special:Mostlinkedtemplates]] – <span lang="en" dir="ltr" class="mw-content-ltr">shows the templates with the most uses</span> * [[Special:Unusedtemplates]] – <span lang="en" dir="ltr" class="mw-content-ltr">shows templates with no uses (although they may be substituted)</span> * {{ll|Manual:$wgEnableScaryTranscluding}} – <span lang="en" dir="ltr" class="mw-content-ltr">using templates from other wikis</span> * [[w:Wikipedia:Template namespace]]<!-- Moved here from [[Transclusion]] because it seemed more fitting, but no idea how redundant this is at this point. Chealer 20250706 --> * [[w:WP:Anatomy of a template]] * [[w:Wikipedia:Transclusion costs and benefits]] * [[Manual:Parser.php]] * {{ll|Help:Extension:TemplateSandbox}} – <span lang="en" dir="ltr" class="mw-content-ltr">for previewing your changes to a template as it renders elsewhere</span> * {{ll|Manual:HTML templates}} <div lang="en" dir="ltr" class="mw-content-ltr"> == External links == </div> * [https://dev.miraheze.org/wiki/Miraheze_Developers_Wiki <span lang="en" dir="ltr" class="mw-content-ltr">Miraheze template repository</span>] – <span lang="en" dir="ltr" class="mw-content-ltr">MediaWiki templates intended for general use.</span> {{help}} [[Category:Help{{#translation:}}|Templates]] [[Category:Templates{{#translation:}}]] [[Category:MediaWiki for site admins{{#translation:}}]]
Search
Search
Export translations
Add topic