Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Help:Template
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===System variables and conditional logic=== Template code often makes use of the variables and parser functions described at [[Help:Magic words]] to make the template's behavior depend on the environment in which it is included (such as the current time or namespace). Parser functions can be used for some arithmetic calculations and string manipulations on variables and parameter values, but certain standard programming features such as loops and variable assignment are not available. Full string manipulation is not available; some templates providing such function have been created, but they are inefficient and imperfect. Some of the most frequently used variables and functions are listed below. For more, see [[Help:Magic words]] and the fuller documentation at the MediaWiki pages [[mw:Help:Magic words]] and [[mw:Help:Extension:ParserFunctions]]. {| class="wikitable" style="text-align:center;" width="100%" |+Examples of core parser functions ! width="30%" | Description !! width="40%" | wiki source !! width="30%" | Displayed text |- | Uppercasing text | <syntaxhighlight lang="wikitext" inline>{{uc: Heavens to BETSY! }}</syntaxhighlight> | {{uc: Heavens to BETSY! }} |- | Lowercasing text | <syntaxhighlight lang="wikitext" inline>{{lc: Heavens to BETSY! }}</syntaxhighlight> | {{lc: Heavens to BETSY! }} |- | Getting a namespace name | <syntaxhighlight lang="wikitext" inline>{{NS: 1 }}</syntaxhighlight> | {{NS: 1 }} |- | Getting a Wikipedia URL | <syntaxhighlight lang="wikitext" inline>{{fullurl: pagename }}</syntaxhighlight> | {{fullurl: pagename }} |} The ParserFunctions extension provides more programming-oriented parser functions: {| class="wikitable" style="text-align:center;" width="100%" |+Examples of extension parser functions ! width="30%" | Description !! width="40%" | Wiki source !! width="30%" | Displayed text |- | rowspan="2" | Testing for equality between two strings (or parameters). If the first two parameters are equal, the third parameter is returned, otherwise the fourth parameter is returned. | <syntaxhighlight lang="wikitext" inline>{{#ifeq: yes | yes | Hooray...! | Darn...! }}</syntaxhighlight> | {{#ifeq: yes | yes | Hooray...! | Darn...! }} |- | <syntaxhighlight lang="wikitext" inline>{{#ifeq: yes | no | Hooray...! | Darn...! }}</syntaxhighlight> | {{#ifeq: yes | no | Hooray...! | Darn...! }} |- | Testing whether a string (or parameter) contains anything (other than whitespace). If it does, the second parameter is returned, otherwise the third parameter is returned. | <syntaxhighlight lang="wikitext" inline>{{#if: {{{param|}}} | Hooray...! | Darn...! }}</syntaxhighlight> | {{#if: {{{param|}}} | Hooray...! | Darn...! }} |- | [[Help:Calculation|Making a calculation (mathematics)]]<br />[area of circle of radius 4, to 3 decimal places] | <syntaxhighlight lang="wikitext" inline>{{#expr: ( pi * 4 ^ 2 ) round 3 }}</syntaxhighlight> | {{#expr: ( pi * 4 ^ 2 ) round 3 }} |- | [[Help:Calculation|Testing the result of a calculation]]. If the expression is true or non-zero, the second parameter is returned, otherwise the third parameter is returned.<br />[is 1230 even or odd?] | <syntaxhighlight lang="wikitext" inline>{{#ifexpr: 1.23E+3 mod 2 | Odd | Even }}</syntaxhighlight> | {{#ifexpr: 1.23E+3 mod 2 | Odd | Even }} |} {| class="wikitable" style="text-align:center;" width="100%" |+Examples of system variables ! width="30%" | Description !! width="40%" | Wiki source !! width="30%" | Displayed text (for this help page) |- | rowspan="2" | Page names | <syntaxhighlight lang="wikitext" inline>{{PAGENAME}}</syntaxhighlight> | {{PAGENAME}} |- | <syntaxhighlight lang="wikitext" inline>{{FULLPAGENAME}}</syntaxhighlight> | {{FULLPAGENAME}} |- | Name of the current namespace | <syntaxhighlight lang="wikitext" inline>{{NAMESPACE}}</syntaxhighlight> | {{NAMESPACE}} |- | Number of registered users | <syntaxhighlight lang="wikitext" inline>{{NUMBEROFUSERS}}</syntaxhighlight> | {{NUMBEROFUSERS}} |- | Number of pages in a given category | <syntaxhighlight lang="wikitext" inline>{{PAGESINCATEGORY:"Weird Al" Yankovic albums}}</syntaxhighlight> | {{PAGESINCATEGORY:"Weird Al" Yankovic albums}} |- | Current software version | <syntaxhighlight lang="wikitext" inline>{{CURRENTVERSION}}</syntaxhighlight> | {{CURRENTVERSION}} |- | Timestamp of last page revision | <syntaxhighlight lang="wikitext" inline>{{REVISIONTIMESTAMP}}</syntaxhighlight> | {{REVISIONTIMESTAMP}} |} The <syntaxhighlight lang="wikitext" inline>{{PAGENAME}}</syntaxhighlight> and <syntaxhighlight lang="wikitext" inline>{{NAMESPACE}}</syntaxhighlight>variables are particularly useful, and frequently used, to change template behavior based on the context in which they are included. Templates that contain category links often do this. For example, a cleanup template contains a category link to categorize the calling page as one which needs cleanup, so the template is likely to condition that category link on the <syntaxhighlight lang="wikitext" inline>{{NAMESPACE}}</syntaxhighlight> variable so that talk pages, user pages, and any other pages that might call the template incidentally do not get categorized as pages needing cleanup.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)