Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Help:Transclusion
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Template parameters<span class="anchor" id="Template transclusion"></span>=== <!-- Keep anchor as used for all section links globally --> {{further|Help:Template#Parameters}} {{for|a quick guide to templates|Help:A quick guide to templates}} The most common use of transclusion on Wikipedia is for [[Help:Template|templates]]. Templates are specially designed pages intended to be included in other pages using either transclusion or [[Help:Substitution|substitution]]. The standard syntax for transcluding a template titled {{Xtn|Template:Pagename}} is <syntaxhighlight lang="wikitext" inline="">{{Pagename}}</syntaxhighlight>. Additionally, many templates support [[Parameter|parameters]], which are variables that allow templates to function in different ways by passing specific values, also termed ''[[Parameter (computer programming)#Parameters and arguments|arguments]]''. Templates may have no parameters, use a fixed number of parameters, or support a variable number of parameters. The number of parameters a template can accept ranges from one to multiple, depending on its design. The exact syntax for using parameters varies by template. However, for a hypothetical template titled {{Xtn|Template:Pagename}} that accepts three parameters, the general format would be: <syntaxhighlight lang="wikitext" inline="">{{Pagename|parameter1|parameter2|parameter3}}</syntaxhighlight> {{shortcut|WP:UNNAMED|WP:POSPARAM|WP:POSITIONAL}} Where each parameter in a template can be substituted with either a <code>value</code> or a {{Para|parameter name|value}} format when used in practice. Notice that each parameter is separated by a [[vertical bar]] (<code>|</code>). Parameters that take the form <code>value</code> are called ''unnamed'' or ''positional parameters'', while those in the form {{Para|parameter name|value}} are known as ''named parameters''. With unnamed parameters, the first, second, and third parameters correspond to {{Para|1}}, {{Para|2}}, {{Para|3}}, respectively, etc., in [[Wikipedia:Template documentation|template documentation]]. Unnamed parameters must be provided in the correct order and are best placed before named parameters.{{Refn|Otherwise using <code>value</code> on its own will not work, and the unnamed parameters must be called using their 'names', such as {{para|1|value}}, if named parameters precede them.|group=lower-alpha}} For example, using the {{Xtn|[[Template:Collapse top]]}} with two unnamed parameters and one named parameter: : {{y}} <syntaxhighlight lang="wikitext" inline="">{{Collapse top|This is the title text|This is a custom warning line|left=true}}</syntaxhighlight> : {{y}} <syntaxhighlight lang="wikitext" inline="">{{Collapse top|left=true|1=This is the title text|2=This is a custom warning line}}</syntaxhighlight> : {{n}} <syntaxhighlight lang="wikitext" inline="" style="background-color:#ffdad3;">{{Collapse top|left=true|This is the title text|2=This is a custom warning line}}</syntaxhighlight> In this case, <code>This is the title text</code> and <code>This is a custom warning line</code> are the values of unnamed parameters {{Para|1}} and {{Para|2}}, while <code>true</code> is the value assigned to the named parameter {{Para|left}}. The last example shows how unnamed parameters should not be used after named parameters without their 'name'. Although this example includes three parameters, {{Xtn|[[Template:Collapse top]]}} can accept a variable number of parameters. For more details, see [[Help:Template]]. Additionally, [[Wikipedia:Template index]] provides a categorized list of templates, including those for mainspace and other namespaces, along with a search function. Template parameters also play a role in the {{section link|#Parametrization method}} of {{Section link|2=Selective transclusion|nopage=y}}, allowing for more dynamic content inclusion.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)