Jump to content

Template:Xpd/doc

From Meta, a Wikimedia project coordination wiki

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.
    • The rendering of this expanded wikitext

Template:Xpd selects one of the following four templates based on the number of unnamed parameters

Separator parameter

[edit]

The default separator is "gives". With gives={{!}}{{!}} to get "||" for use in a table, the same separator is used before the ExpandTemplates link.

Example:

{| class="wikitable"
!wikitext!!result!!ExpandTemplates
|-
|{{xpd|CURRENTDAY|gives={{!}}{{!}}}}
|-
|{{xpd|1=#expr:2+2|gives={{!}}{{!}}}}
|-
|{{xpdn|#expr: 4*|#expr:not 0|>3|gives={{!}}{{!}}}}
|}

gives

wikitext result ExpandTemplates
{{CURRENTDAY}} 26 [2]
{{#expr:2+2}} 4 [3]
{{#expr: 4*{{#expr:not 0}}>3}} 1

Quotes

[edit]

The quotation marks are needed to see spaces and newlines at the start and end of the result:

{{T ast}} gives

In other expand demo templates they are also needed to see spaces and newlines at the start and end of the wikitext, and to get a result independent of whether it starts on a line due to parameter {{{gives}}}.

Limitations

[edit]

This Template:Xpd is a simplified version of some expansion demo templates. If necessary use the proper extended version.

Named parameters and parameter values with equals signs

[edit]

Named parameters are not supported. Neither are equals signs in parameter values of the template or parser function demonstrated.

Examples:

  • {{xpd|1x| p{{=}}q }} gives "{{1x|p=q}}" gives " p=q " [5] - wrong result due to the template call in the parameter; is corrected by substitution and putting nowiki tags in the lefthand side (see below), giving {{1x| p{{=}}q }} gives p=q [6].
  • {{xpd|1x|2= p=q }} gives "{{1x|p=q}}" gives "p=q" [7] - wrong result because the lefthand side would be expanded interpreting p as named parameter, while the righthand side shows the result if the unnamed parameter of 1x has the given value; use {{xpdopec|1x|1|3= p=q }} giving "{{1x|1=p=q}}" gives "p=q" [8] or {{xpdnp|1x|1n=1|1v= p=q }} giving {{1x|1=p=q}} gives p=q [9] (spaces and newlines are trimmed).
  • {{xpd|t np|q=s}} gives: {{t np}} gives p{{{q}}}r [10] ("q=s" is ignored); instead, use {{xpdopec|t np|q|s}} giving "{{t np|q=s}}" gives "psr" [11] or {{xpdnp|t np|1n=q|1v=s}} giving {{t np|q=s}} gives psr [12].

Even in the case of a parser function called with a parameter containing an equals sign the template for named parameters should be used:

  • {{xpd|#if:x|p=q}} gives: {{#if:x}} gives [13] ("p=q" is ignored); instead, use {{xpdnp|#if:x|1n=p|1v=q}} giving {{#if:x|p=q}} gives p=q [14].

Spaces and newlines

[edit]

If parameters start or end with a space or newline, these are preserved. Even if the left-hand side, as mentioned, does not show the raw wikitext of the parameters but the rendering, the right-hand side gives the correct result.

Example with two newlines, hence also the left-hand side is correct:

"{{xpd|t2| p |

q

}}" gives ""{{t2| p |

q

}}" gives "Parameter 1 is " p ", parameter 2 is "

q

"" [15]" [16]


Example without consecutive spaces inside a parameter value, hence also the left-hand side is correct:

""{{xpd|concat| p | q }}" gives ""{{concat| p | q }}" gives " p q " [17]" [18]"

Substitution

[edit]
  • {{subst:xpd|substnp=subst:|tc}} gives the wikitext {{xpd0|tc}}
  • {{subst:xpd|substnp=subst:|t1|p}} gives the wikitext {{xpd1|t1|p}}
  • {{subst:xpd|substnp=subst:|t2|p|q}} gives the wikitext {{xpd2|t2|p|q}}
  • {{subst:xpd|substnp=subst:|concat|p|q|r}} gives the wikitext {{xpd3|concat|p|q|r}}

Note that except in the case of long and complicated parameters, adding the number of parameters after "xpd" is easier than adding "subst:" and "|substnp=subst:".

With substitution of xpd1 etc. and putting nowiki tags around the list of parameters the left hand side is given literally without conversions, see also above.


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}}" [19]