Help:Expansion
From Wikipedia, the free encyclopedia
View this page using: |
[http://en.wikipedia.org../../../../articles/e/x/p/Help%7EExpansion_ca4a.html |
new preprocessor |
diff |
- The description applies to the new preprocessor.
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{{semicolon}}2*3}} gives:
{{#exprTemplate:Semicolon2*3}}
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
- m:Template:1= (backlinks, edit) containing "1={{{1}}}"
- m:Template:p1=x (backlinks, edit) containing "{{{1=x}}}"
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}}}
Compare:
{{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:Demo template]]</noinclude>" and template:t2demo ( talk edit history links ) containing start-{{{1}}}-middle-{{{2}}}-end) gives start-a-middle-x=y-end.
edit |
Wikipedia-specific help
Template:Ph:Expansion
This page is a copy of the master help page at Meta (for general help information all Wikimedia projects can use), with two Wikipedia-specific templates inserted. To update the main text, edit the master help page for all projects at m:Help:Expansion. For Wikipedia-specific issues, use Template:Ph:Expansion (the extra text at the bottom of this page) or Template:Phh:Expansion for a Wikipedia-specific lead (text appears at the top of this page). You are welcome to replace the full wikitext of this page with that of the master page at Meta at any time. To view this page in other languages see the master page at Meta.