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:Template
(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!
===Nesting templates=== {{shortcut|WP:NEST}} A template may call another template—this is called ''{{dfn|nesting}}'' and the called template is called, in this context, a ''{{dfn|subtemplate}}''. When WikiMedia expands the template, it expands subtemplates as the calls to them appear, so that the final product is essentially the result of expanding templates from the most deeply nested out. While fairly straightforward in application, it involves some noteworthy quirks and tricks. To pass a parameter value from a template call to a subtemplate, use a parameter reference in the template call to the subtemplate. ;Example{{colon}} :Template:A contains <syntaxhighlight lang="wikitext" inline>"the quick brown {{B|{{{3}}} }} jumps over..."</syntaxhighlight>. Template:B (a subtemplate) contains <syntaxhighlight lang="moin" inline>'''{{{1}}}'''</syntaxhighlight>. Page X calls A with <syntaxhighlight lang="wikitext" inline>{{A|apple|pear|fox}}</syntaxhighlight> This expands to <syntaxhighlight lang="wikitext" inline>"the quick brown '''fox''' jumps over..."</syntaxhighlight>. The third unnamed parameter passed to Template:A gets passes as the first unnamed parameter to subtemplate B. A template can even choose which subtemplate parameter to pass conditionally. ;Examples{{colon}} :Template:A contains <syntaxhighlight lang="wikitext" inline>the quick brown {{B|{{{3}}}=fox}} jumps over...</syntaxhighlight>. Template:B (a subtemplate) contains <syntaxhighlight lang="moin" inline>'''{{{jumper}}}'''</syntaxhighlight>. Page X calls A with <syntaxhighlight lang="wikitext" inline>{{A|apple|pear|jumper}}</syntaxhighlight>. This expands to <syntaxhighlight lang="wikitext" inline>"the quick brown '''fox''' jumps over..."</syntaxhighlight>. The third unnamed parameter passed to Template:A is passed as the name of the parameter passed to subtemplate B with the value "fox". {{shortcut|WP:TEMPLATE LOOP}} Template recursion is not available; that is, a template may not call itself directly, or indirectly by calling other templates which call it. Attempts to do so will result in an error message describing a "template loop". When a subtemplate contains unmatched braces—as in <syntaxhighlight lang="text" inline>{{lb}}}</syntaxhighlight>—the unmatched braces are treated as text during processing—they do not affect the parsing of braces in the calling template. But where the template is substituted, the unmatched braces will be parsed as braces when the page is subsequently displayed. This has little practical use, but can occasionally introduce unexpected errors. See [[mw:Manual:Advanced templates]] and [[mw:Manual:Recursive conversion of wikitext]] for more information.
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)