قالب: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

Template:xpd (backlinks edit) selects one of the following four templates based on the number of unnamed parameters

Examples

{{xpd|CURRENTDAY}} gives:

"{{CURRENTDAY}}" gives "١٤" [٢]

{{xpd|#expr:2+2}} gives:

"{{#expr:2+2}}" gives "4" [٣]

For more examples see the separate templates.

Separator parameter

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|#expr:2+2|gives={{!}}{{!}}}}
|}

gives

wikitext result ExpandTemplates
"{{CURRENTDAY}}" "١٤" [٤]
"{{#expr:2+2}}" "4" [٥]

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 {{{gives}}}.

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:

  • {{xpd|1x| p{{=}}q }} gives "{{1x|p=q}}" gives " p=q " [٦] - 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 [٧].
  • {{xpd|1x|2= p=q }} gives "{{1x|p=q}}" gives "p=q" [٨] - 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" [٩] or {{xpdn|1x|1n=1|1v= p=q }} giving {{1x{{ {{{2}}}}}}} gives {{1x{{{{{2}}}}}}} (spaces and newlines are trimmed).
  • {{xpd|2x|q=s}} gives: "{{2x}}" gives "{{{1}}}{{{1}}}" [١٠] ("q=s" is ignored); instead, use {{xpdopec|2x|q|s}} giving "{{2x|q=s}}" gives "{{{1}}}{{{1}}}" [١١] or {{xpdn|2x|1n=q|1v=s}} giving {{2x{{ {{{2}}}}}}} gives {{2x{{{{{2}}}}}}}.

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 "" [١٢] ("p=q" is ignored); instead, use {{xpdn|#if:x|1n=p|1v=q}} giving {{#if:x{{ {{{2}}}}}}} gives .

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; m:Template:xpdn (backlinks edit) covers the simpler of such cases.

Examples:


{{xpd|1x|[[Help:Link]]}}

{{xpd|tl|p
q}}

gives:


"{{1x|[[Help:Link]]}}" gives "Help:Link" [١٣]

"{{tl|p q}}" gives "{{[[Template:p q|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

  • {{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

  • m:Template:tlx (backlinks edit) - 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}}" [١٥]

Undocumented (so far):

Other formatting templates

Templates producing specialised formatting effects for given templates, modules or parameters
Code example Effect Notes
{{tl2|Hatnote|lang=fr}} {{hatnote}} Supports linking to sister projects (e.g., fr:Hatnote)
{{tlu|User:Ahunt/SSHFS}} {{User:Ahunt/SSHFS}} Supports linking to any namespace
{{demo|<nowiki>{{Hatnote|lang=fr|Some text}}</nowiki>}} خطأ: لا توجد وحدة بهذا الاسم "Demo". Shows code and example
{{xpd|Hatnote|Some hatnote text}} "{{hatnote|Some hatnote text}}" gives "خطأ: لا توجد وحدة بهذا الاسم "Hatnote"." [١٦] Shows code, example and a link to expand the template code
{{tln|Hatnote}} Template:Hatnote Produces a normal link to the template
{{elc|Template:Hatnote}}
{{elc|Template:Hatnote|Hatnote}}
[[Template:Hatnote]]
[[Template:Hatnote|Hatnote]]
Formats wikilink, with optional piped link text and blended suffix
{{ml|Example|hello}} {{خطأ: لا توجد وحدة بهذا الاسم "Separated entries".}} Counterpart to {{tl}} for linking to Lua modules
{{mlx|Example|hello}} {{خطأ: لا توجد وحدة بهذا الاسم "Separated entries".}} Counterpart to {{tlx}} for linking to Lua modules
{{para|title|<var>book title</var>}} |title=book title Formats template parameters for display, with or without values
{{sclx|LASTING}} [[[[خطأ في التعبير: عامل < غير متوقع.LASTING]]]] Takes a shortcut suffix in project namespace and displays it with brackets and the WP: alias in a <code>...</code> tag.
{{tag|ref}}
{{xtag|templatedata}}
<ref>...</ref>
<templatedata>
Formats [X]HTML tags; can add content, choose opening, closing, or self-closing
{{dtl|Ping project}} {{d:Ping project}} Wikidata counterpart to {{tl}}
{{pf|if}}
{{pf|if|{{{1}}}|true...}}
{{#if}}
{{#if:{{{1}}}|true|false}}
Parser function equivalent to {{tl}}
{{magic word|uc:}} {{[[MW:Help:Magic words#خطأ: لا توجد وحدة بهذا الاسم "string".|uc:]]}} Magic word links