WikiIndex:Parser functions: Difference between revisions
Hoof Hearted (talk | contribs) m (Hoof Hearted moved page WikiIndex:ParserFunctions to WikiIndex:Parser functions without leaving a redirect: grammar) |
Hoof Hearted (talk | contribs) m (fix double redirects) |
||
Line 1: | Line 1: | ||
A ''' | A '''parser function''' is a special kind of [[WikiIndex:Magic words|magic word]] that is most useful for [[:Category:Templates|templates]]. | ||
{{TOCright}} | {{TOCright}} | ||
{{stub}} | {{stub}} | ||
Line 18: | Line 18: | ||
==if== | ==if== | ||
Shows different values when entered.<br> | Shows different values when entered.<br> | ||
Code: | ;Code: | ||
<pre>{{ #if: {{{value|}}} | what to show if activated | what to show if not }}</pre> | <pre>{{ #if: {{{value|}}} | what to show if activated | what to show if not }}</pre> | ||
Example: | ;Example: | ||
<pre>{{ #if: {{{1|}}} | The name of this site is {{{1}}}. | This site has an unknown name. }}</pre> | <pre>{{ #if: {{{1|}}} | The name of this site is {{{1}}}. | This site has an unknown name. }}</pre> | ||
Let's say this is included in the template ''[[Template:IfExample|ifExample]]''. If <nowiki>{{ifExample|WikiIndex}}</nowiki> is entered, | Let's say this is included in the template ''[[Template:IfExample|ifExample]]''. If <nowiki>{{ifExample|WikiIndex}}</nowiki> is entered, '{{ifExample|WikiIndex}}' will show up because value was specified, as 'WikiIndex'. <nowiki>{{ifExample|not WikiIndex}}</nowiki> makes '{{ifExample|not WikiIndex}}', because value is specified, as 'not WikiIndex'. <nowiki>{{ifExample}}</nowiki> makes just '{{ifExample}}' because it was left blank. | ||
==ifeq== | ==ifeq== | ||
Line 38: | Line 38: | ||
==switch== | ==switch== | ||
Compares values.<br> | Compares values.<br> | ||
Code: | ;Code: | ||
<pre>{{ #switch: value | <pre>{{ #switch: value | ||
| value1 = what to show if value1 is entered | | value1 = what to show if value1 is entered | ||
Line 45: | Line 45: | ||
| #default = what to show if nothing is entered | | #default = what to show if nothing is entered | ||
}}</pre> | }}</pre> | ||
Example: | ;Example: | ||
<pre>{{ #switch: {{{1}}} | <pre>{{ #switch: {{{1}}} | ||
| a = argh | | a = argh | ||
Line 53: | Line 53: | ||
| #default = nothing | | #default = nothing | ||
}}</pre> | }}</pre> | ||
This is included in the template [[template:switchExample|switchExample]]. <nowiki>{{switchExample|a}}</nowiki> gives | This is included in the template [[template:switchExample|switchExample]]. <nowiki>{{switchExample|a}}</nowiki> gives {{switchExample|a}} because a is entered. <nowiki>{{switchExample}}</nowiki> gives {{switchExample}}, because the template was left blank. <nowiki>{{switchExample|d}}</nowiki> gives '{{switchExample|d}}', because d doesn't exist in the template. | ||
==time== | ==time== |
Revision as of 23:16, 30 April 2017
A parser function is a special kind of magic word that is most useful for templates. Template:TOCright
This WikiIndex:Parser functions article is a 'stub'. You can help by expanding this stub article, thanks. :-)
List
expr
coming soon.
if
Shows different values when entered.
- Code
{{ #if: {{{value|}}} | what to show if activated | what to show if not }}
- Example
{{ #if: {{{1|}}} | The name of this site is {{{1}}}. | This site has an unknown name. }}
Let's say this is included in the template ifExample. If {{ifExample|WikiIndex}} is entered, 'Template:IfExample' will show up because value was specified, as 'WikiIndex'. {{ifExample|not WikiIndex}} makes 'Template:IfExample', because value is specified, as 'not WikiIndex'. {{ifExample}} makes just 'Template:IfExample' because it was left blank.
ifeq
coming soon.
ifexist
coming soon.
ifexpr
coming soon.
rel2abs
coming soon.
switch
Compares values.
- Code
{{ #switch: value | value1 = what to show if value1 is entered | value2 = what to show if value2 is entered | | what to show if something else is entered | #default = what to show if nothing is entered }}
- Example
{{ #switch: {{{1}}} | a = argh | b = blah | c = cough | | anything | #default = nothing }}
This is included in the template switchExample. {{switchExample|a}} gives Template:SwitchExample because a is entered. {{switchExample}} gives Template:SwitchExample, because the template was left blank. {{switchExample|d}} gives 'Template:SwitchExample', because d doesn't exist in the template.
time
coming soon.