Help:Expansion demo templates

From Meta, a Wikimedia project coordination wiki
Jump to: navigation, search

The expansion demo templates (see [1]) show, for documentation:

  • some wikitext
  • its rendering
  • a link to ExpandTemplates applied to the wikitext; thus it shows:
    • The expanded wikitext; this differs from the wikitext if that contains the call of a variable, parser function or template.
    • The rendering of this expanded wikitext (the result of expanding again (bugzilla:28616), and further processing); this is typically the same as how the wikitext is rendered (the result of expanding once and further processing), because typically expanding again causes no further changes. However, there are exceptions; e.g. when calling Template:Txpd: {{txpd}} gives {{1x|p}} [2].

Usage:

{{xpdpattern|parameters}}
{{xpdpattern|l=x|parameters}} - with the template linked

The characters "|" and "=" and the double braces "{{" and "}}" cannot be part of the parameters. Such components of the wikitext determine the pattern. Note that this does not apply for the colon, so e.g. in a parser function everything between the opening braces and the colon, such as "#ifeq:abc", can be taken together as one parameter of xpd, and the pattern is the same as when this is replaced by a template name.

The rendering is based on inline use of the supplied wikitext. To see the result when it is at the start of a new line, put a newline in the wikitext (in a separate parameter, see below). Thus "*a" → "*a" [3], but "
*a"
→ "

Supported patterns[edit]

Below are the supported patterns.[1] There is a separate template for each, because a combined template page gets slow due to all examples, while there is little advantage in having them combined.

pattern template 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
plain Template:Xpdplain " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 "
oc Template:Xpdoc " { { 1 } } 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 "
5oc Template:Xpd5oc " 1 2 3 4 5 { { 6 } } 7 8 9 10 11 12 13 14 15 16 "
10oc Template:Xpd10oc " 1 2 3 4 5 6 7 8 9 10 { { 11 } } 12 13 14 15 16 "
5o5c Template:Xpd5o5c " 1 2 3 4 5 { { 6 7 8 9 10 } } 11 12 13 14 15 16 "
opec Template:Xpdopec " { { 1 | 2 = 3 } } 4 5 6 7 8 9 10 11 12 13 14 "
5opec Template:Xpd5opec " 1 2 3 4 5 { { 6 | 7 = 8 } } 9 10 11 12 13 14 "
op3c Template:Xpdop3c " { { 1 | 2 3 4 } } 5 6 7 8 9 10 11 12 13 14 15 "
o5p5c Template:Xpdo5p5c " { { 1 2 3 4 5 | 6 7 8 9 10 } } 11 12 13 14 15 16 17 "
op3p3c Template:Xpdop3p3c " { { 1 | 2 3 4 | 5 6 7 } } 8 9 10 11 12 13 14 15 16 "
op14c Template:Xpdop14c " { { 1 | 2 3 4 5 6 7 8 9 10 11 12 13 14 15 } } "
op10pec Template:Xpdop10pec " { { 1 | 2 3 4 5 6 7 8 9 10 11 | 12 = 13 } } "
5op3c Template:Xpd5op3c " 1 2 3 4 5 { { 6 | 7 8 9 } } 10 11 12 13 14 15 "
op5cop5c Template:Xpdop5cop5c " { { 1 | 2 3 4 5 6 } } { { 7 | 8 9 10 11 12 } } "
oocc Template:Xpdoocc " { { 1 { { 2 } } } } 3 4 5 6 7 8 9 10 11 12 "
o5occ Template:Xpdo5occ " { { 1 2 3 4 5 { { 6 } } } } 7 8 9 10 11 12 "
opocc Template:Xpdopocc " { { 1 | { { 2 } } } } 3 4 5 6 7 8 9 10 11 "
op4oc5c Template:Xpdop4oc5c " { { 1 | 2 3 4 5 { { 6 } } 7 8 9 10 11 } } "
opopcc Template:Xpdopopcc " { { 1 | { { 2 | 3 } } } } 4 5 6 7 8 9 10 "
op3occ Template:Xpdop3occ " { { 1 | 2 3 4 { { 5 } } } } 6 7 8 9 10 "
opoppcc Template:Xpdopoppcc " { { 1 | { { 2 | 3 | 4 } } } } 5 6 7 8 9 "
5op3p3c Template:Xpd5op3p3c " 1 2 3 4 5 { { 6 | 7 8 9 | 10 11 12 } } 13 14 "
opepec Template:Xpdopepec " { { 1 | 2 = 3 | 4 = 5 } } 6 7 8 9 10 11 12 "
5opepec Template:Xpd5opepec " 1 2 3 4 5 { { 6 | 7 = 8 | 9 = 10 } } 11 12 "
op3pec Template:Xpdop3pec " { { 1 | 2 3 4 | 5 = 6 } } 7 8 9 10 11 12 "
5op3pec Template:Xpd5op3pec " 1 2 3 4 5 { { 6 | 7 8 9 | 10 = 11 } } 13 14 "
5op3p3p3c Template:Xpd5op3p3p3c " 1 2 3 4 5 { { 6 | 7 8 9 | 10 11 12 | 13 14 15 } } "
5op3p3pec Template:Xpd5op3p3pec " 1 2 3 4 5 { { 6 | 7 8 9 | 10 11 12 | 13 = 14 } } "
opepepec Template:Xpdopepepec " { { 1 | 2 = 3 | 4 = 5 | 6 = 7 } } 8 9 10 11 12 "
5opepepec Template:Xpd5opepepec " 1 2 3 4 5 { { 6 | 7 = 8 | 9 = 10 | 11 = 12 } } "

Naming scheme:

  • o = double opening braces
  • c = double closing braces
  • p = pipe character
  • e = equals sign
  • number = number of text parameters (at the start: instead of none; elsewhere: instead of one), to allow a space or newline as value of a separate parameter (this is required for proper processing)

Additional parameters[edit]

  • The parameter gives can be assigned a text (or the empty string) to replace the word "gives", e.g. gives={{!}}{{!}} to produce "||", for use in a table.
  • By default quotation marks are used both around the wikitext and around the result. This is especially useful to show blank spaces and newlines. The optional parameter d can change this delimiter, e.g. "d=" to make it the empty string. Note however that the result including the delimiters is trimmed; this does not affect the default case, but may affect the result if the delimiter is empty, or if the delimiter itself has a newline or space at the start or end.

Examples[edit]

Examples without additional parameters:

{{xpdoc|l=x|tc}} "{{tc}}" → "in" [5]
{{xpdoc|CURRENTDAY}} "{{CURRENTDAY}}" → "18" [6]
{{xpdoc|#expr:2*3}} "{{#expr:2*3}}" → "6" [7]
{{xpdoc|urlencode:!}} "{{urlencode:!}}" → "%21" [8]
{{xpdoc|uc:abc}} "{{uc:abc}}" → "ABC" [9]

If the left side contains an equals sign, the named parameter 1 can and should be used:

{{xpdoc|1=#expr:2+2=4}} "{{#expr:2+2=4}}" → "1" [10]

Equals sign in another parameter: see below.

Expression in double braces which itself includes a pair of double braces (simple nested expressions): use xpdoocc, with "|" for the inner "{{" and, if there is code after it, also for "}}". see also Template:Xpdn

{{xpdoocc|#expr:24*|CURRENTDAY|+3}} "{{#expr:24*{{CURRENTDAY}}+3}}" gives "435" [11]
{{xpdoocc|#expr: 4*|#expr:not 0| >3}} "{{#expr: 4*{{#expr:not 0}} >3}}" gives "1" [12]
{{xpdoocc|formatnum:|#expr:124*125}} "{{formatnum:{{#expr:124*125}}}}" gives "15,500" [13]

Examples with additional parameters (no nesting possible):

{{xpd5op3p3c||||||#ifeq: 1.00|+1|okay}} "{{#ifeq: 1.00|+1|okay}}" gives "okay" [14]
{{xpd|#ifeq: 1.00|+1|okay}} "{{#ifeq: 1.00|+1|okay}}" gives "okay" [15]
{{xpd|#ifeq: this|that||false|s=is}} "{{#ifeq: this|that||false}}" gives "false" [16]
{{xpdop3c|l=x|t1demo| |pqr| }} "{{t1demo| pqr }}" → "start- pqr -end" [17]
{{xpd5op3p3c|l=x||||||t2demo| |b| | |c| }} "{{t2demo| b|&s&sc }}" gives "start- b -middle- c -end" [18]
{{xpd|l=x|t2demo| b | c }} "{{t2demo| b | c }}" gives "start- b -middle- c -end" [19]

For the examples below see also the edit box.

"abcdefghij" → "abcdefghij" [20]

"a
b

c"
→ "a b

c" [21]

"[[a]]b c" → "ab c" [22]

"[[a|b]] c" → "b c" [23]

"
{| class="wikitable sortable"
!pq!!rs
|-
|tu||vw
|-
|xyz||ab
|}"
→ "

pq rs
tu vw
xyz ab

" [24]

Limitations[edit]

Characters in a separate parameter, and combinations of characters together in a separate parameter[edit]

Some characters need to be in a separate parameter, and some combinations of characters need to be together in a separate parameter, so that the template can recognize them and handle them separately:

A newline needs to be in a separate parameter, otherwise it is displayed as a space, while the result takes into account the newline: {{xpdplain|a|
|b|
|
|c}}

gives:

"a
b

c"
→ "a b

c" [25] (correct)

{{xpdplain|a
b

c}}

gives:

"a b c" → "a b

c" [26] (the resulting statement is with respect to the separation between a and b by itself correct, but not what was supposed to be demonstrated, and with respect to the separation between b and c even wrong)

Selection of pattern[edit]

The expansion demo template does not check whether it is the correct one for the pattern of the wikitext. Assume that the wikitext which is the subject of the demonstration contains double braces, but that, due to separation with "|" and the wrong choice of the expansion demo template, they are treated as plain text in the expansion of the expansion demo template call. Then the produced message "..." gives "..." is not correct, because in the expansion of the wikitext at the first set of dots the double braces would be interpreted as template braces etc. Example:

{{xpdplain|{|{tc}|}|}} gives:

"{{tc}}" → "{{tc}}" [27]

although in reality (as shown when selecting the correct expansion demo template xpdoc):

"{{tc}}" → "in" [28]

Technical background[edit]

Each template calls Template:Xpda. See there for more technical explanation.

Notes:

  • Some of the expansion demo templates still specify p=pattern in the call of Template:Xpda. However, this parameter is no longer used and can be removed.
  • Some of the expansion demo templates still specify gives={{{gives|gives}}} in the call of Template:Xpda. However, this is being replaced by gives= while moving the {{{gives|gives}}} to the start of result. This avoids trimming on the left side of the result if delimiter d is specified as the empty string; this trimming is especially inconvenient if the result is a table: quotes do not look good, but the newline before "{|" is needed.

See also[edit]

  • Template:Tlx - produces just the template call, with the template name linked to the template, but not the result, e.g. "{{tlx|t2|b|c}}" gives "{{t2|b|c}}" [29]
  1. In the case of a red link to the template the pattern is not yet supported.