Template:Xpd/doc

The expansion demo templates (see ) 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

xpd selects one of the following four templates based on the number of unnamed parameters
 * xpd0 - simplified version of
 * xpd1 - simplified version of
 * xpd2 - simplified version of
 * xpd3 - simplified version of

Examples
CURRENTDAY gives:

CURRENTDAY


 * 1) expr:2+2 gives:


 * 1) expr:2+2

For more examples see the separate templates.

Separator parameter
The default separator is "gives". With  to get "||" for use in a table, the same separator is used before the ExpandTemplates link.

Example:

gives

Quotes
The quotation marks are needed to see spaces and newlines at the start and end of the result. 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.

Limitations
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
Named parameters are not supported. Neither are equals signs in parameter values of the template or parser function demonstrated.

Examples:
 * 1x gives 1x - 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 {&#123; &#125;} gives [{{fullurl:special:ExpandTemplates|input=%7B%7B{{urlencode:1x{{!}} p{{=}}q } }}%7D}}].
 * 1x gives 1x - 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 giving  or  giving  (spaces and newlines are trimmed).
 * t np gives: t np ("q=s" is ignored); instead, use giving  or  giving.

Even in the case of a parser function called with a parameter containing an equals sign the template for named parameters should be used:
 * #if:x gives: #if:x ("p=q" is ignored); instead, use  giving.

Rendering of left side
If no value for parameter p is given, the left-hand side, before "gives", does not show the literal wikitext of the parameters of the template or parser function demonstrated, but the rendering. This affects e.g. sequences of more than two spaces, and single newlines. Also link code is shown as a link. Furthermore, any templates and parser functions in the parameters are expanded; covers the simpler of such cases.

Examples:

Help:Link

p q

gives:

Help:Link

p q

With substitution of xpd1 etc. (see below) and putting nowiki tags around the list of parameters the left hand side is corrected.

Also the input text of ExpandTemplates in the supplied link is the result of expanding the parameters.

Spaces and newlines
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.

Substitution

 * t1 gives the wikitext
 * t2 gives the wikitext
 * concat gives the wikitext

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.