From Wikipedia, the free encyclopedia
Jump to: navigation, search

Expansion of templates, parser functions, variables, and template parameters is done in substitution, and also as first step in page rendering. The result of this first step is shown with Special:ExpandTemplates (see mw:Extension:ExpandTemplates). For studying the expansion step this intermediate result is more useful than the rendered page, especially in the case of a table and/or when looking into newlines produced.

Wikitext is parsed with respect to patterns such as {{..|..|..=..}}, {{..:..|..|..}}, {{{..}}}, {{{..|..}}}, and [[..|..]], where a dotted part can contain such structures itself, etc. Pipes, semicolons, and equals signs are, as far as applicable, taken as belonging to the innermost structure in which they occur, and never interpreted as part of an outer structure.

For example, using m:Template:t2demo (backlinks edit) containing "start-{{{1}}}-middle-{{{2}}}-end":

  • {{t2demo|a[[b=c|d=e]]f|g}} gives start-ad=ef-middle-g-end

However, for the purpose of expansion in the sense of this page, pairs of single brackets and angle brackets are not recognized as creating special structures:

  • {{t2demo|a[http://b=c d=e]f|g}} gives start-g-middle-{{{2}}}-end
  • {{t2demo|1=a[http://b=c d=e]f|2=g}} gives start-ad=ef-middle-g-end

and, using m:Template:t1demo (backlinks edit) containing "start{{{1}}}end":

  • {{t1demo|a <span style="color:red">red</span> word}} gives start{{{1}}}end
  • {{t1demo|1=a <span style="color:red">red</span> word}} gives starta red wordend

Furthermore, {{#expr{{COLON}}2*3}} gives:


After fully determining which pairs and triples of braces belong together, and which pipes and equals signs belong to the same structure, etc., expansion of the outermost structures starts: for templates, parser functions, variables, and template parameters, the wikitext for the name is expanded. For a template the wikitexts of all parameter names are expanded, and the wikitexts for the names of the formal parameters in the template body, after which it is determined for which parameter values the wikitexts need to be expanded, and for which formal parameters the defaults.

For e.g. parser function #ifexpr, the next step is expanding the condition. Based on that either the wikitext for the then-part or that for the else-part is expanded.

Braces, pipes, semicolons, and equals signs which are produced by expansion are taken as just characters, not parts of structures.

For example, using

we have:

  • {{t1demo|{{{|1=x}}}}} gives start1=xend
  • {{t1demo|{{#if:x|1=x}}}} gives start1=xend
  • {{t1demo|{{1=|x}}}} gives startTemplate:1=end
  • {{t1demo|{{1=|x}}=y}} gives start{{{1}}}end
  • {{p1=x|{{{|1=x}}}=y}} gives y
  • {{p1=x|{{1=|x}}=y}} gives {{{1=x}}}


  • "{{1=|x}}" gives "Template:1=" [1]
  • {{t1demo|1=x}} gives startxend
  • {{t1demo|1=x=y}} gives startx=yend

The examples also show that a parameter name "1=x", although impractical, works.

An example of an equals sign in a parameter value not being interpreted in a parameter definition:

  • {{t2a1|1=x=y}} (using Template:t2a1 containing "{{t2demo|a|{{{1}}}}}<noinclude>[[Category:Help:Templates templates]]</noinclude>" and template:t2demo ( talk edit history links ) containing start-{{{1}}}-middle-{{{2}}}-end) gives start-a-middle-x=y-end.