Help:Expansion

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 containing "start--middle--end":
 * gives

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:
 * gives
 * gives

and, using containing "startend":


 * gives
 * gives

Furthermore, 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
 * containing "1="
 * containing ""

we have:


 * gives
 * gives
 * gives
 * gives
 * gives
 * gives

Compare:
 * 1=
 * gives
 * gives

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:
 * (using and  containing start--middle--end) gives.