Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Numinix MediaWiki Demo
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Help/Templates
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
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!
=== Recursion in templates === <!--T:149--> </translate> <translate><!--T:124--> Including a template in itself won't throw MediaWiki into infinite recursion.</translate> <translate><!--T:125--> MediaWiki will stop the recursion with the template's name in bold.</translate> <translate><!--T:126--> For example, if the content of Template:Aaaa is <tvar name=code><code>a <nowiki></nowiki> z</code></tvar>, it'll display "<tvar name=result>a a <span class="error">Template loop detected: '''Template:Aaaa'''</span> z z</tvar>".</translate> <translate><!--T:219--> This safeguard precludes a potentially useful template idiom where a template self-normalizes its own calling arguments.</translate> <translate><!--T:220--> In this forbidden example <tvar name=1><code>template:d</code></tvar> can either be called <tvar name=2><code><nowiki></nowiki></code></tvar> or <tvar name=3><code><nowiki></nowiki></code></tvar>.</translate> <translate><!--T:221--> 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.</translate> <syntaxhighlight lang="wikitext"> }|}|0|4}}|m=}|4|2}}|d=}|6|2}}}}|<!-- processing path with arguments y,m,d regardless of original call pattern -->}} </syntaxhighlight> <translate><!--T:222--> If <tvar name=1><code>template:d</code></tvar> is modified to recurse into <tvar name=2><code>template:d/2</code></tvar> and <tvar name=3><code>template:d/2</code></tvar> is an ''identical manual copy'' of <tvar name=4><code>template:d</code></tvar> this idiom works fine as the self-recursion safeguard operates dynamically and not statically.</translate> <translate><!--T:223--> 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.</translate> <translate><!--T:224--> That would provide a strong guarantee against infinite self-recursion while enabling useful idioms such as the one described here in a flexible manner.</translate> <translate><!--T:225--> 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.</translate> <translate><!--T:226--> 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.</translate> <translate>
Summary:
Please note that all contributions to Numinix MediaWiki Demo may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Project:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)