Template:Example Stack
| This template uses Lua: |
Calls {{Template example}} for each set of parameters.
Parameters within each set are separated by \, and the sets themselves are separated by |. The template name is taken from the current page title, up to the first slash, but it can be specified explicitly using |t= (or |template=).
Many of the parameters used by {{Template example}} are available, but without the leading underscore: |style=, |sep=, |nobr=, |spaced=, |nocat=, |prefix=, and |postfix=. Within individual examples, you can use \_alias=, \_prefix=, and \_postfix=, as well as \_comment=, \_after=, and \_before= to annotate the example (but take care with equals signs; see below). The character at the start of each line is set using |opener= (the default is : , which creates an indent). Wikitext to insert between examples is supplied using |between= (for example, {{^}}; the default is an empty string, except when |style=*pre is used, in which case the value is {{^|3em}}).
The template also supports substitution. |syntaxhighlight= is set to true by default.
Examples
[edit]{{Example Stack|t{{=}}Allcaps|apple|banana|carrot}}
{{Allcaps|apple}}→ apple{{Allcaps|banana}}→ banana{{Allcaps|carrot}}→ carrot
To make the code easier to read, you can put each set of parameters on a separate line:
{{Example Stack|t=Allcaps
|apple
|banana
|carrot\_comment{{=}}(Converts the text to uppercase.)
}}
{{Allcaps|apple}}→ apple{{Allcaps|banana}}→ banana{{Allcaps|carrot}}→ carrot (Converts the text to uppercase.)
Unlike {{Template example}}, {{tc}}, and some other templates, literal equals signs do not work directly, so use {{=}} instead. Also, if your template uses parameter names that begin with an underscore, use _ in its place. If your examples contain many named parameters, it is convenient to use N= at the start of each line to specify the parameter number, for example:
{{Example Stack|t=#invoke:Example|style=wikitable|spaced=1
|1=count_fruit\apples=3\bananas=5
|2=count_fruit\apples=1\bananas=1
|3=count_fruit\apples=Not a number\bananas=Not a number
}}
| Code | Result |
|---|---|
{{#invoke:Example |count_fruit |apples=3 |bananas=5 }} |
I have 5 bananas and 3 apples |
{{#invoke:Example |count_fruit |apples=1 |bananas=1 }} |
I have 1 banana and 1 apple |
{{#invoke:Example |count_fruit |apples=Not a number |bananas=Not a number }} |
I have 0 bananas and 0 apples |
By default, leading and trailing spaces and line breaks are trimmed from unnamed parameters (separated by |). To disable this behavior, use |trim=0. However, if you use N= at the beginning of a line, those parameters will still be trimmed, because this behavior is built into the parser.
TemplateData
[edit]TemplateData for Example Stack
TemplateData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Displays a stack of template or Lua module examples by calling Template example for each set of arguments
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||