Help:Expansion depth

From Meta, a Wikimedia project coordination wiki
Jump to: navigation, search
MediaWiki Handbook: Contents, Readers, Editors, Moderators, System admins +/-

Expansion of templates, parser functions, variables (on this page collectively called templates in italics), and template parameters (tplargs) is subject to an expansion depth limit of 40. It regards the step of producing the expanded wikitext. This step can be isolated from the step of rendering the expanded wikitext by using Special:ExpandTemplates.

The expansion depth is related to the situation that to expand a template or tplarg, expansion of other templates or tplargs is needed. The latter can be in the title or parts in the wikitext to be expanded itself, or in the wikitext of a directly or indirectly called template. How exactly the depth is counted is not always straightforward, see also below.

The highest expansion depth is shown in the limit report in the html source[1]. This improvement of the MediaWiki software was made after what follows was written. This probably makes it easier to investigate expansion depth issues, allowing simpler tests, not exceeding the limit.

The relevant PHP source code includes the preprocessor function "expand", in Manual:Preprocessor DOM.php, which expands a wikitext. If it is a title and variable $expansionDepth (incremented at the start and decremented at the end of the function; inside the function it is incremented through recursion) is greater than mMaxPPExpandDepth then the wikitext <span class="error">Expansion depth limit exceeded</span> rendered as Expansion depth limit exceeded[2] is returned.

As far as the result with the error message can be expanded it is expanded as usual.

In the case of double braces, since "<" and ">" are not allowed in a page title, the braced structure is not transcluded, nor rendered as a link to a non-existing template. However, a parameter tag still works, with the parameter name replaced by the error message.

Examples:

<code>0 {{#tag:nowiki |1 {{#if:x|2 {{#if:x|3 {{#if:x|4 {{#if:x|5 {{#if:x|6 {{#if:x|7 {{#if:x|8 {{#if:x|9 {{#if:x|10 {{#if:x|11 {{#if:x|12 {{#if:x|13 {{#if:x|14 {{#if:x|15 {{#if:x|16 {{#if:x|17 {{#if:x|18 {{#if:x|19 {{#if:x|20 {{#if:x|21 {{#if:x|22 {{#if:x|23 {{#if:x|24 {{#if:x|25 {{#if:x|26 {{#if:x|27 {{#if:x|28 {{#if:x|29 {{#if:x|30 {{#if:x|31 {{#if:x|32 {{#if:x|33 {{#if:x|34 {{#if:x|35 {{#if:x|36 {{#if:x|37 {{#if:x|38 {{#if:x|39 {{#if:x|40 a {{b|c}} {{#if:x|d}} {{PAGENAME}} {{{e}}} {{{e|f}}} {{xpdt/1|g|h}} 40}} {{xpdt/1|i|j}} {{xpdt/25|k}} {{#ifeq:123|{{#if:x|123}}|1|0}} {{#expr:123={{#if:x|123}}}} 40 {{tc}} 39}} 38}} 37}} 36}} 35}} 34}} 33}} 32}} 31}} 30}} 29}} 28}} 27}} 26}} 25}} 24}} 23}} 22}} 21}} 20}} 19}} 18}} 17}} 16}} 15}} 14}} 13}} 12}} 11}} 10}} 9}} 8}} 7}} 6}} 5}} 4}} 3}} 2}} 1}} 0 </code> gives 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 a {{<span class="error">Expansion depth limit exceeded</span>|c}} {{<span class="error">Expansion depth limit exceeded</span>|d}} {{<span class="error">Expansion depth limit exceeded</span>}} {{{<span class="error">Expansion depth limit exceeded</span>}}} f {{<span class="error">Expansion depth limit exceeded</span>|g|h}} 40 [[Template:Xpdt/1]]: in i ifx ifin 1xin [[Template:Xpdt/25]]: *'''if:''' 012345678910111213141516171819202122232425k252423222120191817161514131211109876543210 *'''1x:''' 01234567891011121314151617181920{{<span class="error">Expansion depth limit exceeded</span>|21{{<span class="error">Expansion depth limit exceeded</span>|22{{<span class="error">Expansion depth limit exceeded</span>|23{{<span class="error">Expansion depth limit exceeded</span>|24{{<span class="error">Expansion depth limit exceeded</span>|25{{{<span class="error">Expansion depth limit exceeded</span>}}}25}}24}}23}}22}}21}}20191817161514131211109876543210 0 <strong class="error">Expression error: Unrecognized punctuation character "{".</strong> 40 in 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

This demonstrates:

  • The conversion of titles at level 41.
  • Template:Xpdt/1 and even Template:Xpdt/25 called at level 40 work, even though especially the latter has also many parser function levels.
  • When the error message ends up in an expression, the result contains somewhat cryptically an error message about a wrong expression, not about the expansion depth. Worse, when the error message ends up in a condition, the result may be deceptively wrong without any error message.

{{Help:Expansion depth|e=v}} gives:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 a {{<span class="error">Expansion depth limit exceeded</span>|c}} {{<span class="error">Expansion depth limit exceeded</span>|d}} {{<span class="error">Expansion depth limit exceeded</span>}} {{{<span class="error">Expansion depth limit exceeded</span>}}} f {{<span class="error">Expansion depth limit exceeded</span>|g|h}} 40 [[Template:Xpdt/1]]: {{<span class="error">Expansion depth limit exceeded</span>|1}} {{{<span class="error">Expansion depth limit exceeded</span>}}} {{<span class="error">Expansion depth limit exceeded</span>|ifx}} {{<span class="error">Expansion depth limit exceeded</span>|if{{<span class="error">Expansion depth limit exceeded</span>|1}}}} {{<span class="error">Expansion depth limit exceeded</span>|1x{{<span class="error">Expansion depth limit exceeded</span>|1}}}} [[Template:Xpdt/25]]: *'''if:''' 0{{<span class="error">Expansion depth limit exceeded</span>|1{{<span class="error">Expansion depth limit exceeded</span>|2{{<span class="error">Expansion depth limit exceeded</span>|3{{<span class="error">Expansion depth limit exceeded</span>|4{{<span class="error">Expansion depth limit exceeded</span>|5{{<span class="error">Expansion depth limit exceeded</span>|6{{<span class="error">Expansion depth limit exceeded</span>|7{{<span class="error">Expansion depth limit exceeded</span>|8{{<span class="error">Expansion depth limit exceeded</span>|9{{<span class="error">Expansion depth limit exceeded</span>|10{{<span class="error">Expansion depth limit exceeded</span>|11{{<span class="error">Expansion depth limit exceeded</span>|12{{<span class="error">Expansion depth limit exceeded</span>|13{{<span class="error">Expansion depth limit exceeded</span>|14{{<span class="error">Expansion depth limit exceeded</span>|15{{<span class="error">Expansion depth limit exceeded</span>|16{{<span class="error">Expansion depth limit exceeded</span>|17{{<span class="error">Expansion depth limit exceeded</span>|18{{<span class="error">Expansion depth limit exceeded</span>|19{{<span class="error">Expansion depth limit exceeded</span>|20{{<span class="error">Expansion depth limit exceeded</span>|21{{<span class="error">Expansion depth limit exceeded</span>|22{{<span class="error">Expansion depth limit exceeded</span>|23{{<span class="error">Expansion depth limit exceeded</span>|24{{<span class="error">Expansion depth limit exceeded</span>|25{{{<span class="error">Expansion depth limit exceeded</span>}}}25}}24}}23}}22}}21}}20}}19}}18}}17}}16}}15}}14}}13}}12}}11}}10}}9}}8}}7}}6}}5}}4}}3}}2}}1}}0 *'''1x:''' 0{{<span class="error">Expansion depth limit exceeded</span>|1{{<span class="error">Expansion depth limit exceeded</span>|2{{<span class="error">Expansion depth limit exceeded</span>|3{{<span class="error">Expansion depth limit exceeded</span>|4{{<span class="error">Expansion depth limit exceeded</span>|5{{<span class="error">Expansion depth limit exceeded</span>|6{{<span class="error">Expansion depth limit exceeded</span>|7{{<span class="error">Expansion depth limit exceeded</span>|8{{<span class="error">Expansion depth limit exceeded</span>|9{{<span class="error">Expansion depth limit exceeded</span>|10{{<span class="error">Expansion depth limit exceeded</span>|11{{<span class="error">Expansion depth limit exceeded</span>|12{{<span class="error">Expansion depth limit exceeded</span>|13{{<span class="error">Expansion depth limit exceeded</span>|14{{<span class="error">Expansion depth limit exceeded</span>|15{{<span class="error">Expansion depth limit exceeded</span>|16{{<span class="error">Expansion depth limit exceeded</span>|17{{<span class="error">Expansion depth limit exceeded</span>|18{{<span class="error">Expansion depth limit exceeded</span>|19{{<span class="error">Expansion depth limit exceeded</span>|20{{<span class="error">Expansion depth limit exceeded</span>|21{{<span class="error">Expansion depth limit exceeded</span>|22{{<span class="error">Expansion depth limit exceeded</span>|23{{<span class="error">Expansion depth limit exceeded</span>|24{{<span class="error">Expansion depth limit exceeded</span>|25{{{<span class="error">Expansion depth limit exceeded</span>}}}25}}24}}23}}22}}21}}20}}19}}18}}17}}16}}15}}14}}13}}12}}11}}10}}9}}8}}7}}6}}5}}4}}3}}2}}1}}0 0 <strong class="error">Expression error: Unrecognized punctuation character "{".</strong> 40 in 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

This shows that parameter e is not effective where it is changed on expansion into the error message. It also shows that calling (the include part of) this page, although creating just one extra level, causes all levels of Template:Xpdt/25 to be counted.

{{Help:Expansion depth|<span class{{=}}"error">Expansion depth limit exceeded</span>=w}} gives:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 a {{<span class="error">Expansion depth limit exceeded</span>|c}} {{<span class="error">Expansion depth limit exceeded</span>|d}} {{<span class="error">Expansion depth limit exceeded</span>}} w w {{<span class="error">Expansion depth limit exceeded</span>|g|h}} 40 [[Template:Xpdt/1]]: {{<span class="error">Expansion depth limit exceeded</span>|1}} {{{<span class="error">Expansion depth limit exceeded</span>}}} {{<span class="error">Expansion depth limit exceeded</span>|ifx}} {{<span class="error">Expansion depth limit exceeded</span>|if{{<span class="error">Expansion depth limit exceeded</span>|1}}}} {{<span class="error">Expansion depth limit exceeded</span>|1x{{<span class="error">Expansion depth limit exceeded</span>|1}}}} [[Template:Xpdt/25]]: *'''if:''' 0{{<span class="error">Expansion depth limit exceeded</span>|1{{<span class="error">Expansion depth limit exceeded</span>|2{{<span class="error">Expansion depth limit exceeded</span>|3{{<span class="error">Expansion depth limit exceeded</span>|4{{<span class="error">Expansion depth limit exceeded</span>|5{{<span class="error">Expansion depth limit exceeded</span>|6{{<span class="error">Expansion depth limit exceeded</span>|7{{<span class="error">Expansion depth limit exceeded</span>|8{{<span class="error">Expansion depth limit exceeded</span>|9{{<span class="error">Expansion depth limit exceeded</span>|10{{<span class="error">Expansion depth limit exceeded</span>|11{{<span class="error">Expansion depth limit exceeded</span>|12{{<span class="error">Expansion depth limit exceeded</span>|13{{<span class="error">Expansion depth limit exceeded</span>|14{{<span class="error">Expansion depth limit exceeded</span>|15{{<span class="error">Expansion depth limit exceeded</span>|16{{<span class="error">Expansion depth limit exceeded</span>|17{{<span class="error">Expansion depth limit exceeded</span>|18{{<span class="error">Expansion depth limit exceeded</span>|19{{<span class="error">Expansion depth limit exceeded</span>|20{{<span class="error">Expansion depth limit exceeded</span>|21{{<span class="error">Expansion depth limit exceeded</span>|22{{<span class="error">Expansion depth limit exceeded</span>|23{{<span class="error">Expansion depth limit exceeded</span>|24{{<span class="error">Expansion depth limit exceeded</span>|25{{{<span class="error">Expansion depth limit exceeded</span>}}}25}}24}}23}}22}}21}}20}}19}}18}}17}}16}}15}}14}}13}}12}}11}}10}}9}}8}}7}}6}}5}}4}}3}}2}}1}}0 *'''1x:''' 0{{<span class="error">Expansion depth limit exceeded</span>|1{{<span class="error">Expansion depth limit exceeded</span>|2{{<span class="error">Expansion depth limit exceeded</span>|3{{<span class="error">Expansion depth limit exceeded</span>|4{{<span class="error">Expansion depth limit exceeded</span>|5{{<span class="error">Expansion depth limit exceeded</span>|6{{<span class="error">Expansion depth limit exceeded</span>|7{{<span class="error">Expansion depth limit exceeded</span>|8{{<span class="error">Expansion depth limit exceeded</span>|9{{<span class="error">Expansion depth limit exceeded</span>|10{{<span class="error">Expansion depth limit exceeded</span>|11{{<span class="error">Expansion depth limit exceeded</span>|12{{<span class="error">Expansion depth limit exceeded</span>|13{{<span class="error">Expansion depth limit exceeded</span>|14{{<span class="error">Expansion depth limit exceeded</span>|15{{<span class="error">Expansion depth limit exceeded</span>|16{{<span class="error">Expansion depth limit exceeded</span>|17{{<span class="error">Expansion depth limit exceeded</span>|18{{<span class="error">Expansion depth limit exceeded</span>|19{{<span class="error">Expansion depth limit exceeded</span>|20{{<span class="error">Expansion depth limit exceeded</span>|21{{<span class="error">Expansion depth limit exceeded</span>|22{{<span class="error">Expansion depth limit exceeded</span>|23{{<span class="error">Expansion depth limit exceeded</span>|24{{<span class="error">Expansion depth limit exceeded</span>|25{{{<span class="error">Expansion depth limit exceeded</span>}}}25}}24}}23}}22}}21}}20}}19}}18}}17}}16}}15}}14}}13}}12}}11}}10}}9}}8}}7}}6}}5}}4}}3}}2}}1}}0 0 <strong class="error">Expression error: Unrecognized punctuation character "{".</strong> 40 in 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

This shows that occurrences of parameter e which are converted to the error message are effective as parameter with the error message as name.

Nesting depth on the page itself[edit]

To start with, the nesting of templates or tplargs on the page itself cannot be deeper than 40 levels, where a template call is counted once (not once for expanding the template and once for expanding a parameter, the latter is not on the page itself but on the template page, compare the next section).

Thus, for example,

0 {{1x|1 {{1x|2 {{1x|3 {{1x|4 {{1x|5 {{1x|6 {{1x|7 {{1x|8 {{1x|9 {{1x|10 {{1x|11 {{1x|12 {{1x|13 {{1x|14 {{1x|15 {{1x|16 {{1x|17 {{1x|18 {{1x|19 {{1x|20 {{1x|21 {{1x|22 {{1x|23 {{1x|24 {{1x|25 {{1x|26 {{1x|27 {{1x|28 {{1x|29 {{1x|30 {{1x|31 {{1x|32 {{1x|33 {{1x|34 {{1x|35 {{1x|36 {{1x|37 {{1x|38 {{1x|39 {{1x|40 {{tc|1}} 40}} 39}} 38}} 37}} 36}} 35}} 34}} 33}} 32}} 31}} 30}} 29}} 28}} 27}} 26}} 25}} 24}} 23}} 22}} 21}} 20}} 19}} 18}} 17}} 16}} 15}} 14}} 13}} 12}} 11}} 10}} 9}} 8}} 7}} 6}} 5}} 4}} 3}} 2}} 1}} 0

gives

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 {{Expansion depth limit exceeded|1}} 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

and, replacing two template calls by parser function calls:

0 {{#if:x|1 {{#if:x|2 {{1x|3 {{1x|4 {{1x|5 {{1x|6 {{1x|7 {{1x|8 {{1x|9 {{1x|10 {{1x|11 {{1x|12 {{1x|13 {{1x|14 {{1x|15 {{1x|16 {{1x|17 {{1x|18 {{1x|19 {{1x|20 {{1x|21 {{1x|22 {{1x|23 {{1x|24 {{1x|25 {{1x|26 {{1x|27 {{1x|28 {{1x|29 {{1x|30 {{1x|31 {{1x|32 {{1x|33 {{1x|34 {{1x|35 {{1x|36 {{1x|37 {{1x|38 {{1x|39 {{1x|40 {{tc|1}} 40}} 39}} 38}} 37}} 36}} 35}} 34}} 33}} 32}} 31}} 30}} 29}} 28}} 27}} 26}} 25}} 24}} 23}} 22}} 21}} 20}} 19}} 18}} 17}} 16}} 15}} 14}} 13}} 12}} 11}} 10}} 9}} 8}} 7}} 6}} 5}} 4}} 3}} 2}} 1}} 0

gives

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 {{Expansion depth limit exceeded|1}} 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Caching[edit]

If on a page the same template is called more than once without parameters, the first result is cached. It may have been cached before too. Thus, when investigating expansion depth issues, always call all templates with a parameter, even if the template body does not contain any parameter tags.

Overall nesting depth[edit]

In a chain of nested templates, where at every level except the last, a parameter of the template contains a call to the next template in the chain, the overall depth also depends of the depths inside the templates. The previous section dealt with the simplest case, such as Template:1x, counting for 1, allowing a chain of length 40 containing any mix of parser functions and such basic templates.

When a template in the chain has itself a nesting of templates and/or parser functions, with at the end a parameter (with as value the remaining chain on the root page), the extra template calls are counted twice and the extra parser function calls once. However, a number of levels equal to the number of extra template calls can be reused for levels in the chain on the root page beyond this template.

For example:


0 {{1x|1 {{1x|2 {{xpdt/3|3 {{1x|4 {{1x|5 {{1x|6 {{1x|7 {{1x|8 {{1x|9 {{1x|10 {{1x|11 {{1x|12 {{1x|13 {{1x|14 {{1x|15 {{1x|16 {{1x|17 {{1x|18 {{1x|19 {{1x|20 {{1x|21 {{1x|22 {{1x|23 {{1x|24 {{1x|25 {{1x|26 {{1x|27 {{1x|28 {{1x|29 {{1x|30 {{1x|31 {{1x|32 {{1x|33 {{1x|34 {{1x|35 {{1x|36 {{1x|37 {{1x|38 {{1x|39 {{1x|40 {{tc|1}} 40}} 39}} 38}} 37}} 36}} 35}} 34}} 33}} 32}} 31}} 30}} 29}} 28}} 27}} 26}} 25}} 24}} 23}} 22}} 21}} 20}} 19}} 18}} 17}} 16}} 15}} 14}} 13}} 12}} 11}} 10}} 9}} 8}} 7}} 6}} 5}} 4}} 3}} 2}} 1}} 0

gives

0 1 2 Template:Xpdt/3:

  • if: 01233 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 {{{Expansion depth limit exceeded}}} 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 33210
  • 1x: 01233 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 {{{Expansion depth limit exceeded}}} 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 33210
2 1 0

0 {{1x|1 {{1x|2 {{1x|3 {{1x|4 {{1x|5 {{1x|6 {{1x|7 {{1x|8 {{1x|9 {{1x|10 {{1x|11 {{1x|12 {{1x|13 {{1x|14 {{1x|15 {{1x|16 {{1x|17 {{1x|18 {{1x|19 {{1x|20 {{1x|21 {{1x|22 {{1x|23 {{1x|24 {{1x|25 {{1x|26 {{1x|27 {{1x|28 {{1x|29 {{1x|30 {{1x|31 {{1x|32 {{1x|33 {{xpdt/3|34 {{1x|35 {{1x|36 {{1x|37 {{1x|38 {{1x|39 {{1x|40 {{tc|1}} 40}} 39}} 38}} 37}} 36}} 35}} 34}} 33}} 32}} 31}} 30}} 29}} 28}} 27}} 26}} 25}} 24}} 23}} 22}} 21}} 20}} 19}} 18}} 17}} 16}} 15}} 14}} 13}} 12}} 11}} 10}} 9}} 8}} 7}} 6}} 5}} 4}} 3}} 2}} 1}} 0

gives

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Template:Xpdt/3:

  • if: 012334 35 36 37 {{{Expansion depth limit exceeded}}} 37 36 35 343210
  • 1x: 012334 35 36 37 {{{Expansion depth limit exceeded}}} 37 36 35 343210
33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 {{1x|1 {{1x|2 {{1x|3 {{1x|4 {{1x|5 {{1x|6 {{1x|7 {{1x|8 {{1x|9 {{1x|10 {{1x|11 {{1x|12 {{1x|13 {{1x|14 {{1x|15 {{1x|16 {{1x|17 {{1x|18 {{1x|19 {{1x|20 {{1x|21 {{1x|22 {{1x|23 {{1x|24 {{1x|25 {{1x|26 {{1x|27 {{1x|28 {{1x|29 {{1x|30 {{1x|31 {{1x|32 {{1x|33 {{1x|34 {{xpdt/3|35 {{1x|36 {{1x|37 {{1x|38 {{1x|39 {{1x|40 {{tc|1}} 40}} 39}} 38}} 37}} 36}} 35}} 34}} 33}} 32}} 31}} 30}} 29}} 28}} 27}} 26}} 25}} 24}} 23}} 22}} 21}} 20}} 19}} 18}} 17}} 16}} 15}} 14}} 13}} 12}} 11}} 10}} 9}} 8}} 7}} 6}} 5}} 4}} 3}} 2}} 1}} 0

gives

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 Template:Xpdt/3:

  • if: 012335 36 37 {{{Expansion depth limit exceeded}}} 37 36 353210
  • 1x: 0123{{{Expansion depth limit exceeded}}}3210
34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 {{1x|1 {{1x|2 {{1x|3 {{1x|4 {{1x|5 {{1x|6 {{1x|7 {{1x|8 {{1x|9 {{1x|10 {{1x|11 {{1x|12 {{1x|13 {{1x|14 {{1x|15 {{1x|16 {{1x|17 {{1x|18 {{1x|19 {{1x|20 {{1x|21 {{1x|22 {{1x|23 {{1x|24 {{1x|25 {{1x|26 {{1x|27 {{1x|28 {{1x|29 {{1x|30 {{1x|31 {{1x|32 {{1x|33 {{1x|34 {{1x|35 {{xpdt/3|36 {{1x|37 {{1x|38 {{1x|39 {{1x|40 {{tc|1}} 40}} 39}} 38}} 37}} 36}} 35}} 34}} 33}} 32}} 31}} 30}} 29}} 28}} 27}} 26}} 25}} 24}} 23}} 22}} 21}} 20}} 19}} 18}} 17}} 16}} 15}} 14}} 13}} 12}} 11}} 10}} 9}} 8}} 7}} 6}} 5}} 4}} 3}} 2}} 1}} 0

gives

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 Template:Xpdt/3:

  • if: 012336 37 {{{Expansion depth limit exceeded}}} 37 363210
  • 1x: 012{{{Expansion depth limit exceeded}}}210
35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 {{1x|1 {{1x|2 {{1x|3 {{1x|4 {{1x|5 {{1x|6 {{1x|7 {{1x|8 {{1x|9 {{1x|10 {{1x|11 {{1x|12 {{1x|13 {{1x|14 {{1x|15 {{1x|16 {{1x|17 {{1x|18 {{1x|19 {{1x|20 {{1x|21 {{1x|22 {{1x|23 {{1x|24 {{1x|25 {{1x|26 {{1x|27 {{1x|28 {{1x|29 {{1x|30 {{1x|31 {{1x|32 {{1x|33 {{1x|34 {{1x|35 {{1x|36 {{xpdt/3|37 {{1x|38 {{1x|39 {{1x|40 {{tc|1}} 40}} 39}} 38}} 37}} 36}} 35}} 34}} 33}} 32}} 31}} 30}} 29}} 28}} 27}} 26}} 25}} 24}} 23}} 22}} 21}} 20}} 19}} 18}} 17}} 16}} 15}} 14}} 13}} 12}} 11}} 10}} 9}} 8}} 7}} 6}} 5}} 4}} 3}} 2}} 1}} 0

gives

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 Template:Xpdt/3:

  • if: 012337 {{{Expansion depth limit exceeded}}} 373210
  • 1x: 012{{Expansion depth limit exceeded|3{{{Expansion depth limit exceeded}}}3}}210
36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Thus, for the 1x branch, if 7 remaining levels are available at the level of the xpdt/3, this is enough, and 3 levels are reused for levels beyond this templates. By contrast, if only 6 remaining levels are available at the level of the xpdt/3, this is not enough, the parameter is not expanded, so anything in the chain on the root page beyond this template (i.e., at a deeper level, serving as value for the parameter) is discarded.

Transcluding a template[edit]

Consider the special case of a page transcluding a template. This is a "chain" of length 1. When this template has a nesting of templates and/or parser functions, with at the end a parameter, these template calls are counted twice and these parser function calls once, see Help:Expansion depth/demo.

As the demo shows, the template can, for example, have 20 nested basic templates. If one of the nested templated is Template:Xpdt/3 (with three extra transclusion levels), the chain can contain together up to 18 templates ((40-3)/2, rounded down), while xpdt/3 cannot be the 18th position in the chain. If two are xpdt/3, the chain can contain together up to 17 templates ((40-6)/2), while the second xpdt/3 cannot be beyond the 15th position in the chain.

More generally, if the template contains a chain of m templates like the 1x-branch of xpdt/nk (for nk=0: like 1x) the restriction is that for every k with 1 ≤ k ≤ m the sum of (ni+2) over all i with 1 ≤ i ≤ k, plus nk, is less than or equal to 40.

Edt[edit]

In the following example this page calls Template:Edt, which calls Template:Xpdt/25. First there is the expansion of Edt, then of its parameter 1, then 0 or more calls of #if or 1x, then the expansion of template Xpdt/25.

The 1x-part of the first item succeeds in the expansion of a chain of 19 expansions of template 1x and its parameter, and another expansion of template 1x without expanding its parameter. The 1x-part of the second item has extra one expansion of 1x and its parameter in Edt, and one less of each in Xpdt/25, etc. The if-part of item 8 has 7 expansions of 1x and its parameter in Edt, and 25 expansions of parser function #if in Xpdt/25. The if-part of item 9 has 8 expansions of 1x and its parameter in Edt, and 23 expansions of #if in Xpdt/25, etc. Thus, not counting the expansion of Edt and its parameter 1, and of template Xpdt/25, there is in all cases a depth of 39 expansions. Comparing this with the previous example we see that the expansion of parameter 1 of Edt does not contribute to the expansion depth. Comparing with the earlier examples we see that the extra template is counted, since a depth of 39 remains, while before is was 40. w:Template:Transclusion depth test also indicates that in a chain of templates each counts as 1.

Item 21 has 20 expansions of 1x and its parameter in Edt, and no expansion of Edt. Thus, not counting the expansion of Edt and its parameter 1, there is a depth of 40 expansions.

{{edt|xpdt/25}} gives:

Expansion depth test (purge)

edt 0

Template:Xpdt/25:

  • if: 0123456789101112131415161718192021222324251252423222120191817161514131211109876543210
  • 1x: 012345678910111213141516171819{{{Expansion depth limit exceeded}}}191817161514131211109876543210


edt 1

Template:Xpdt/25:

  • if: 0123456789101112131415161718192021222324251252423222120191817161514131211109876543210
  • 1x: 0123456789101112131415161718{{{Expansion depth limit exceeded}}}1817161514131211109876543210


edt 2

Template:Xpdt/25:

  • if: 0123456789101112131415161718192021222324251252423222120191817161514131211109876543210
  • 1x: 01234567891011121314151617{{{Expansion depth limit exceeded}}}17161514131211109876543210


edt 3

Template:Xpdt/25:

  • if: 0123456789101112131415161718192021222324251252423222120191817161514131211109876543210
  • 1x: 012345678910111213141516{{{Expansion depth limit exceeded}}}161514131211109876543210


edt 4

Template:Xpdt/25:

  • if: 0123456789101112131415161718192021222324251252423222120191817161514131211109876543210
  • 1x: 0123456789101112131415{{{Expansion depth limit exceeded}}}1514131211109876543210


edt 5

Template:Xpdt/25:

  • if: 0123456789101112131415161718192021222324251252423222120191817161514131211109876543210
  • 1x: 01234567891011121314{{{Expansion depth limit exceeded}}}14131211109876543210


edt 6

Template:Xpdt/25:

  • if: 0123456789101112131415161718192021222324251252423222120191817161514131211109876543210
  • 1x: 012345678910111213{{{Expansion depth limit exceeded}}}131211109876543210


edt 7

Template:Xpdt/25:

  • if: 012345678910111213141516171819202122232425{{{Expansion depth limit exceeded}}}252423222120191817161514131211109876543210
  • 1x: 0123456789101112{{{Expansion depth limit exceeded}}}1211109876543210


edt 8

Template:Xpdt/25:

  • if: 01234567891011121314151617181920212223{{Expansion depth limit exceeded|24{{Expansion depth limit exceeded|25{{{Expansion depth limit exceeded}}}25}}24}}23222120191817161514131211109876543210
  • 1x: 01234567891011{{{Expansion depth limit exceeded}}}11109876543210


edt 9

Template:Xpdt/25:

  • if: 0123456789101112131415161718192021{{Expansion depth limit exceeded|22{{Expansion depth limit exceeded|23{{Expansion depth limit exceeded|24{{Expansion depth limit exceeded|25{{{Expansion depth limit exceeded}}}25}}24}}23}}22}}2120191817161514131211109876543210
  • 1x: 012345678910{{{Expansion depth limit exceeded}}}109876543210


edt 10

Template:Xpdt/25:

  • if: 012345678910111213141516171819{{Expansion depth limit exceeded|20{{Expansion depth limit exceeded|21{{Expansion depth limit exceeded|22{{Expansion depth limit exceeded|23{{Expansion depth limit exceeded|24{{Expansion depth limit exceeded|25{{{Expansion depth limit exceeded}}}25}}24}}23}}22}}21}}20}}191817161514131211109876543210
  • 1x: 0123456789{{{Expansion depth limit exceeded}}}9876543210


edt 11

Template:Xpdt/25:

  • if: 01234567891011121314151617{{Expansion depth limit exceeded|18{{Expansion depth limit exceeded|19{{Expansion depth limit exceeded|20{{Expansion depth limit exceeded|21{{Expansion depth limit exceeded|22{{Expansion depth limit exceeded|23{{Expansion depth limit exceeded|24{{Expansion depth limit exceeded|25{{{Expansion depth limit exceeded}}}25}}24}}23}}22}}21}}20}}19}}18}}17161514131211109876543210
  • 1x: 012345678{{{Expansion depth limit exceeded}}}876543210


edt 12

Template:Xpdt/25:

  • if: 0123456789101112131415{{Expansion depth limit exceeded|16{{Expansion depth limit exceeded|17{{Expansion depth limit exceeded|18{{Expansion depth limit exceeded|19{{Expansion depth limit exceeded|20{{Expansion depth limit exceeded|21{{Expansion depth limit exceeded|22{{Expansion depth limit exceeded|23{{Expansion depth limit exceeded|24{{Expansion depth limit exceeded|25{{{Expansion depth limit exceeded}}}25}}24}}23}}22}}21}}20}}19}}18}}17}}16}}1514131211109876543210
  • 1x: 01234567{{{Expansion depth limit exceeded}}}76543210


edt 13

Template:Xpdt/25:

  • if: 012345678910111213{{Expansion depth limit exceeded|14{{Expansion depth limit exceeded|15{{Expansion depth limit exceeded|16{{Expansion depth limit exceeded|17{{Expansion depth limit exceeded|18{{Expansion depth limit exceeded|19{{Expansion depth limit exceeded|20{{Expansion depth limit exceeded|21{{Expansion depth limit exceeded|22{{Expansion depth limit exceeded|23{{Expansion depth limit exceeded|24{{Expansion depth limit exceeded|25{{{Expansion depth limit exceeded}}}25}}24}}23}}22}}21}}20}}19}}18}}17}}16}}15}}14}}131211109876543210
  • 1x: 0123456{{{Expansion depth limit exceeded}}}6543210


edt 14

Template:Xpdt/25:

  • if: 01234567891011{{Expansion depth limit exceeded|12{{Expansion depth limit exceeded|13{{Expansion depth limit exceeded|14{{Expansion depth limit exceeded|15{{Expansion depth limit exceeded|16{{Expansion depth limit exceeded|17{{Expansion depth limit exceeded|18{{Expansion depth limit exceeded|19{{Expansion depth limit exceeded|20{{Expansion depth limit exceeded|21{{Expansion depth limit exceeded|22{{Expansion depth limit exceeded|23{{Expansion depth limit exceeded|24{{Expansion depth limit exceeded|25{{{Expansion depth limit exceeded}}}25}}24}}23}}22}}21}}20}}19}}18}}17}}16}}15}}14}}13}}12}}11109876543210
  • 1x: 012345{{{Expansion depth limit exceeded}}}543210


edt 15

Template:Xpdt/25:

  • if: 0123456789{{Expansion depth limit exceeded|10{{Expansion depth limit exceeded|11{{Expansion depth limit exceeded|12{{Expansion depth limit exceeded|13{{Expansion depth limit exceeded|14{{Expansion depth limit exceeded|15{{Expansion depth limit exceeded|16{{Expansion depth limit exceeded|17{{Expansion depth limit exceeded|18{{Expansion depth limit exceeded|19{{Expansion depth limit exceeded|20{{Expansion depth limit exceeded|21{{Expansion depth limit exceeded|22{{Expansion depth limit exceeded|23{{Expansion depth limit exceeded|24{{Expansion depth limit exceeded|25{{{Expansion depth limit exceeded}}}25}}24}}23}}22}}21}}20}}19}}18}}17}}16}}15}}14}}13}}12}}11}}10}}9876543210
  • 1x: 01234{{{Expansion depth limit exceeded}}}43210


edt 16

Template:Xpdt/25:

  • if: 01234567{{Expansion depth limit exceeded|8{{Expansion depth limit exceeded|9{{Expansion depth limit exceeded|10{{Expansion depth limit exceeded|11{{Expansion depth limit exceeded|12{{Expansion depth limit exceeded|13{{Expansion depth limit exceeded|14{{Expansion depth limit exceeded|15{{Expansion depth limit exceeded|16{{Expansion depth limit exceeded|17{{Expansion depth limit exceeded|18{{Expansion depth limit exceeded|19{{Expansion depth limit exceeded|20{{Expansion depth limit exceeded|21{{Expansion depth limit exceeded|22{{Expansion depth limit exceeded|23{{Expansion depth limit exceeded|24{{Expansion depth limit exceeded|25{{{Expansion depth limit exceeded}}}25}}24}}23}}22}}21}}20}}19}}18}}17}}16}}15}}14}}13}}12}}11}}10}}9}}8}}76543210
  • 1x: 0123{{{Expansion depth limit exceeded}}}3210


edt 17

Template:Xpdt/25:

  • if: 012345{{Expansion depth limit exceeded|6{{Expansion depth limit exceeded|7{{Expansion depth limit exceeded|8{{Expansion depth limit exceeded|9{{Expansion depth limit exceeded|10{{Expansion depth limit exceeded|11{{Expansion depth limit exceeded|12{{Expansion depth limit exceeded|13{{Expansion depth limit exceeded|14{{Expansion depth limit exceeded|15{{Expansion depth limit exceeded|16{{Expansion depth limit exceeded|17{{Expansion depth limit exceeded|18{{Expansion depth limit exceeded|19{{Expansion depth limit exceeded|20{{Expansion depth limit exceeded|21{{Expansion depth limit exceeded|22{{Expansion depth limit exceeded|23{{Expansion depth limit exceeded|24{{Expansion depth limit exceeded|25{{{Expansion depth limit exceeded}}}25}}24}}23}}22}}21}}20}}19}}18}}17}}16}}15}}14}}13}}12}}11}}10}}9}}8}}7}}6}}543210
  • 1x: 012{{{Expansion depth limit exceeded}}}210


edt 18

Template:Xpdt/25:

  • if: 0123{{Expansion depth limit exceeded|4{{Expansion depth limit exceeded|5{{Expansion depth limit exceeded|6{{Expansion depth limit exceeded|7{{Expansion depth limit exceeded|8{{Expansion depth limit exceeded|9{{Expansion depth limit exceeded|10{{Expansion depth limit exceeded|11{{Expansion depth limit exceeded|12{{Expansion depth limit exceeded|13{{Expansion depth limit exceeded|14{{Expansion depth limit exceeded|15{{Expansion depth limit exceeded|16{{Expansion depth limit exceeded|17{{Expansion depth limit exceeded|18{{Expansion depth limit exceeded|19{{Expansion depth limit exceeded|20{{Expansion depth limit exceeded|21{{Expansion depth limit exceeded|22{{Expansion depth limit exceeded|23{{Expansion depth limit exceeded|24{{Expansion depth limit exceeded|25{{{Expansion depth limit exceeded}}}25}}24}}23}}22}}21}}20}}19}}18}}17}}16}}15}}14}}13}}12}}11}}10}}9}}8}}7}}6}}5}}4}}3210
  • 1x: 01{{{Expansion depth limit exceeded}}}10


edt 19

Template:Xpdt/25:

  • if: 01{{Expansion depth limit exceeded|2{{Expansion depth limit exceeded|3{{Expansion depth limit exceeded|4{{Expansion depth limit exceeded|5{{Expansion depth limit exceeded|6{{Expansion depth limit exceeded|7{{Expansion depth limit exceeded|8{{Expansion depth limit exceeded|9{{Expansion depth limit exceeded|10{{Expansion depth limit exceeded|11{{Expansion depth limit exceeded|12{{Expansion depth limit exceeded|13{{Expansion depth limit exceeded|14{{Expansion depth limit exceeded|15{{Expansion depth limit exceeded|16{{Expansion depth limit exceeded|17{{Expansion depth limit exceeded|18{{Expansion depth limit exceeded|19{{Expansion depth limit exceeded|20{{Expansion depth limit exceeded|21{{Expansion depth limit exceeded|22{{Expansion depth limit exceeded|23{{Expansion depth limit exceeded|24{{Expansion depth limit exceeded|25{{{Expansion depth limit exceeded}}}25}}24}}23}}22}}21}}20}}19}}18}}17}}16}}15}}14}}13}}12}}11}}10}}9}}8}}7}}6}}5}}4}}3}}2}}10
  • 1x: 0{{{Expansion depth limit exceeded}}}0



A way of reducing expansion depth of a versatile template is splitting it up, as has been partially done with Template:If. See also the following subsection.

Switch[edit]

A single #switch is effectively a nesting of branching functions, without counting each level. Thus in some cases a nesting of branching functions can be replaced by a switch, reducing the depth count.

For example:

  • {{#switch:1|condition1=branch1|condition2=branch2|condition3=branch3|branch4}}

is equivalent with

  • {{#ifexpr:condition1|branch1|{{#ifexpr:condition2|branch2|{{#ifexpr:condition3|branch3|branch4}}}}}}

See also[edit]

  1. MediaWiki revision: Show Highest expansion depth in limit report
  2. The message is explicitly given the source code, not as a reference to a system message in the MediaWiki namespace. There is also message with id 'parser-template-recursion-depth-warning' (talk).

Links to other help pages[edit]

Help contents
Meta · Wikinews · Wikipedia · Wikiquote · Wiktionary · Commons: · Wikidata · Mediawiki · Wikibooks · Wikisource · Mediawiki:Manual · Google
Versions of this help page (for other languages see further)
What links here on Meta or from Meta · Wikipedia · MediaWiki
Reading
Go · Search · Stop words · Namespace · Page name · Section · Backlinks · Redirect · Category · Image page · Special pages · Printable version
Tracking changes
Recent changes (enhanced) | Related changes · Watching pages · Diff · Page history · Edit summary · User contributions · Minor edit · Patrolled edit
Logging in and preferences
Logging in · Preferences · User style
Editing
Starting a new page · Advanced editing · Editing FAQ · Edit toolbar · Export · Import · Shortcuts · Edit conflict · Page size
Referencing
Links · URLs · Piped links · Interwiki linking · Footnotes
Style and formatting
Wikitext examples · CSS · Reference card · HTML in wikitext · Formula · List · Table · Sorting · Colors · Images and file uploads
Fixing mistakes
Show preview · Testing · Reverting edits
Advanced functioning
Expansion · Template · Advanced templates · Parser function · Parameter default · Variable · System message · Substitution · Array · Calculation · Embed page
Others
Special characters · Renaming (moving) a page · Preparing a page for translation · Talk page · Signatures · Sandbox · Legal issues for editors
Languages: English