Help:Extension:ParserFunctions

From VistApedia
Jump to navigationJump to search

<languages/> <translate> The {{<tvar|ext-pf>mediawiki|Extension:ParserFunctions</>|ParserFunctions}} extension provides eleven additional parser functions to supplement the "{{<tvar|help-magic>mediawiki|Special:MyLanguage/Help:Magic words#Parser functions</>|magic words}}", which are already present in MediaWiki. (It may be configured to provide additional parser functions for string handling; these string functions are documented {{<tvar|ext-sf>mediawiki|Extension:StringFunctions#Functions</>|elsewhere}}.) All the parser functions provided by this extension take the form:</translate>

{{<translate> #functionname: argument 1 | argument 2 | argument 3 ... </translate>}}

#expr

<translate> Type</translate> <translate> Operators</translate>
<translate> Grouping (parentheses)</translate> ( )
<translate> Numbers</translate> 1234.5   e (2.718)   pi (3.142)
<translate> binary operator</translate> e   <translate> unary</translate> +,-
<translate> Unary</translate> not ceil trunc floor abs exp ln sin cos tan acos asin atan
<translate> Binary</translate> ^
* / div mod
+ -
<translate> Round</translate> round
<translate> Logic</translate> = != <> > < >= <=
and
or

<translate> This function evaluates a mathematical expression and returns the calculated value.</translate> <translate> This function is also available in {{<tvar|ext-scribunto>mediawiki|Extension:Scribunto</>|Scribunto}} via the <tvar|expr>mw.ext.ParserFunctions.expr</> function.</translate>

{{#expr: <translate> expression</translate> }}

<translate> The available operators are listed to the right, in order of precedence. See {{<tvar|meta-calc>mediawiki|m:Special:MyLanguage/Help:Calculation</>|Help:Calculation}} for more details of the function of each operator. The accuracy and format of the result returned will vary depending on the operating system of the server running the wiki and the number format of the site language.

When evaluating using boolean algebra, zero evaluates to false, and any nonzero value, positive or negative, evaluates to true:</translate>

{{#expr: 1 and -1 }}1
{{#expr: 1 and 0 }}0
{{#expr: 1 or -1 }}1
{{#expr: -1 or 0 }}1
{{#expr: 0 or 0 }}0

<translate> An empty input expression returns an empty string. Invalid expressions return one of several error messages, which can be caught using the <tvar|iferror>#iferror</> function:</translate>

{{#expr: }}
{{#expr: 1+ }}Expression error: Missing operand for +.
{{#expr: 1 = }}Expression error: Missing operand for =.
{{#expr: 1 foo 2 }}Expression error: Unrecognized word "foo".

<translate> The order of addition and subtraction operands before or after a number is meaningful and may be treated as a positive or negative value instead of as an operand with an erroneous input:</translate>

{{#expr: +1 }}1
{{#expr: -1 }}-1
{{#expr: + 1 }}1
{{#expr: - 1 }}-1

<translate> Note, if using the output of magic words, you must raw-format them in order to remove commas and translate the numerals. For example, <tvar|numberofusers>{{NUMBEROFUSERS}}</> results in <tvar|nou-result>331</>, where we want <tvar|nou-result-raw>331</>, which can be obtained using <tvar|numberofusers2>{{formatnum:{{NUMBEROFUSERS}}|R}}</>. This is especially important in some languages, where numerals are translated. For example, in Bengali, <tvar|numberofusers3>{{NUMBEROFUSERS}}</> produces <tvar|bengali>৩০,০৬১</>.</translate>

{{#expr:{{NUMBEROFUSERS}}+100}} 431
{{#expr:{{formatnum:{{NUMBEROFUSERS}}|R}}+100}}431

Script error: No such module "Template translation". {{ Script error: No such module "Template translation".

 |1=time>{{#time: xNU }}</>, then you can simply add and subtract dates as numbers.</translate>
 |2=reminder
 |demo=
 }}

<translate>

Rounding

[<tvar|php>http://php.net/manual/en/function.round.php</> Rounds] off the number on the left to a multiple of 1/10 raised to a power, with the exponent equal to the truncated value of the number given on the right.

To round up or down use unary <tvar|ceil>ceil</> or <tvar|floor>floor</> respectively.</translate>

<translate> Test case</translate> <translate> Result</translate> <translate> Method of rounding</translate>
{{#expr: 1/3 round 5 }} 0.33333 <translate> Final digit is < 5, so no apparent rounding occurs</translate>
{{#expr: 1/6 round 5 }} 0.16667 <translate> Final digit is ≥ 5, so it is rounded up</translate>
{{#expr: 8.99999/9 round 5 }} 1 <translate> Again, the result is rounded up on the last digit, which results in additional rounding</translate>
{{#expr: 1234.5678 round -2 }} 1200 <translate> Rounded to nearest 100 because negative values round to the left of the decimal point</translate>
{{#expr: 1234.5678 round 2 }} 1234.57 <translate> Rounded to nearest 100th because positive values round to the right of the decimal point</translate>
{{#expr: 1234.5678 round 2.3 }} 1234.57 <translate> Decimals in the rounding index make no difference in the rounded result</translate>
{{#expr: trunc 1234.5678 }} 1234 <translate> Decimal portion truncated (chopped off)</translate>
<translate> Rounding to the nearest integer</translate>
{{#expr: 1/3 round 0 }} 0 <translate> Down to the nearest integer, which is zero</translate>
{{#expr: 1/2 round 0 }} 1 <translate> Up to the nearest integer, which is one</translate>
{{#expr: 3/4 round 0 }} 1 <translate> Up to the nearest integer, which is one</translate>
{{#expr: -1/3 round 0 }} -0 <translate> Up to the nearest integer, which is zero</translate>
{{#expr: -1/2 round 0 }} -1 <translate> Down to the nearest integer, which is negative one</translate>
{{#expr: -3/4 round 0 }} -1 <translate> Down to the nearest integer, which is negative one</translate>
<translate> Rounding up or down with ceil and floor</translate>
{{#expr: ceil(1/3) }} 1 <translate> Up to the next larger integer, which is one</translate>
{{#expr: floor(1/3) }} 0 <translate> Down to the next smaller integer, which is zero</translate>
{{#expr: ceil(-1/3) }} -0 <translate> Up to the next larger integer, which is zero</translate>
{{#expr: floor(-1/3) }} -1 <translate> Down to the next smaller integer, which is negative one</translate>
{{#expr: ceil 1/3 }} 0.33333333333333 <translate> Not rounded, since 1 already is an integer</translate>
Script error: No such module "Template translation".

<translate>

Strings

Expressions only work with number-like values, they cannot compare strings or characters. <tvar|ifeq>#ifeq</> can be used instead. </translate>

{{#expr: "a" = "a" }}Expression error: Unrecognized punctuation character """.
{{#expr: a = a }}Expression error: Unrecognized word "a".
{{#ifeq: a | a | 1 | 0 }}1

#if

<translate> This function evaluates a test string and determines whether or not it is empty. A test string containing only white space is considered to be empty.</translate>

{{#if: <translate> test string</translate> | <translate> value if test string is not empty</translate> | <translate> value if test string is empty (or only white space)</translate> }}
{{#if: <translate> first parameter</translate> | <translate> second parameter</translate> | <translate> third parameter</translate> }}

<translate> This function first tests whether the first parameter is not empty. If the first parameter is not empty the function displays the second argument. If the first parameter is empty or contains only whitespace characters (spaces, newlines, etc.) it displays the third argument. </translate>

{{#if: | yes | no}}no
{{#if: string | yes | no}}yes
{{#if:      | yes | no}}no
{{#if:


| yes | no}}
no

<translate> The test string is always interpreted as pure text, so mathematical expressions are not evaluated: </translate>

{{#if: 1==2 | yes | no }}yes
{{#if: 0 | yes | no }}yes

<translate> The last parameter (false) may be omitted: </translate>

{{#if: foo | yes }} yes
{{#if: | yes }}
{{#if: foo | | no}}

<translate> The function may be nested. To do so, nest the inner #if function in its full form in place of a parameter of the enclosing #if function. Up to seven levels of nesting is possible, although that may depend on the wiki or a memory limit.

<tvar|code1>{{#if</>: test string | value if test string is not empty | <tvar|code2>{{#if</>: test string | value if test string is not empty | value if test string is empty (or only white space) <tvar|code3>}} }}</>

You can also use a parameter as the test string in your #if statement. You need to ensure you add the <tvar|pipe>|</> (pipe symbol) after the name of the variable.

<tvar|code1>{{#if:{{{1|}}}</>|You entered text in variable 1|There is no text in variable 1 <tvar|code2>}}</>

See {{<tvar|help-pf-tpl>mediawiki|Special:MyLanguage/Help:Parser functions in templates</>|Help:Parser functions in templates}} for more examples of this parser function. </translate>

#ifeq

<translate> This parser function compares two strings and determines whether they are identical. </translate>

{{#ifeq: string 1 | string 2 | value if identical | value if different }}

<translate> If both strings are valid numerical values, the strings are compared numerically: </translate>

{{#ifeq: 01 | 1 | equal | not equal}}equal
{{#ifeq: 0 | -0 | equal | not equal}}equal
{{#ifeq: 1e3 | 1000 | equal | not equal}}equal
{{#ifeq: {{#expr:10^3}} | 1000 | equal | not equal}}equal


<translate> Otherwise the comparison is made as text; this comparison is case sensitive: </translate>

{{#ifeq: foo | bar | equal | not equal}}not equal
{{#ifeq: foo | Foo | equal | not equal}}not equal
{{#ifeq: "01" | "1" | equal | not equal}}not equal  <translate>

(compare to similar example above, without the quotes)</translate>

{{#ifeq: 10^3 | 1000 | equal | not equal}}not equal  <translate> (compare to similar example above, with <tvar|expr>#expr</>)</translate>

<translate> As a practical example, given an existing {{<tvar|help-templates>mediawiki|Special:MyLanguage/Help:Templates</>|template}} Template:Size used to set standard short and long sizes, defined as: </translate>

{{#ifeq: {{{1|}}} | short | 20 | 40}}

<translate> the following ensue: </translate>

{{size|short}}20
{{size|20}}40
{{size}}40

Script error: No such module "Template translation".

Script error: No such module "Template translation".

Script error: No such module "Template translation".

#iferror

<translate> This function takes an input string and returns one of two results; the function evaluates to <tvar|true>true</> if the input string contains an HTML object with <tvar|error>class="error"</>, as generated by other parser functions such as <tvar|expr>#expr</>, <tvar|time>#time</> and <tvar|rel2abs>#rel2abs</>, [[<tvar|templates>Special:MyLanguage/Help:Templates</>|template]] errors such as loops and recursions, and other "failsoft" parser errors. </translate>

{{#iferror: test string | value if error | value if correct }}

<translate> One or both of the return strings can be omitted. If the correct string is omitted, the test string is returned if it is not erroneous. If the error string is also omitted, an empty string is returned on an error: </translate>

{{#iferror: {{#expr: 1 + 2 }} | error | correct }}correct
{{#iferror: {{#expr: 1 + X }} | error | correct }}error
{{#iferror: {{#expr: 1 + 2 }} | error }}3
{{#iferror: {{#expr: 1 + X }} | error }}error
{{#iferror: {{#expr: 1 + 2 }} }}3
{{#iferror: {{#expr: 1 + X }} }}
{{#iferror: {{#expr: . }} | error | correct }}correct
{{#iferror: <strong class="error">a</strong> | error | correct }}error

#ifexpr

<translate> This function evaluates a mathematical expression and returns one of two strings depending on the boolean value of the result: </translate>

{{#ifexpr: expression | value if true | value if false }}

<translate> The expression input is evaluated exactly as for <tvar|expr>#expr</> above, with the same operators being available. The output is then evaluated as a boolean expression.

An empty input expression evaluates to <tvar|false>false</>:</translate>

{{#ifexpr: | yes | no}}no

<translate> As mentioned above, zero evaluates to <tvar|false>false</> and any nonzero value evaluates to <tvar|true>true</>, so this function is equivalent to one using <tvar|ifeq>#ifeq</> and <tvar|expr>#expr</> only:</translate>

{{#ifeq: {{#expr: expression }} | 0 | value if false | value if true }}

<translate> except for an empty or wrong input expression (an error message is treated as an empty string; it is not equal to zero, so we get value if true).</translate>

{{#ifexpr: = | yes | no }} Expression error: Unexpected = operator.

<translate> comparing</translate>

{{#ifeq: {{#expr: = }} | 0 | no | yes }} yes

<translate> Either or both the return values may be omitted; no output is given when the appropriate branch is left empty:</translate>

{{#ifexpr: 1 > 0 | yes }}yes
{{#ifexpr: 1 < 0 | yes }}
{{#ifexpr: 0 = 0 | yes }} yes
{{#ifexpr: 1 > 0 | | no}}
{{#ifexpr: 1 < 0 | | no}} no
{{#ifexpr: 1 > 0 }}

#ifexist

<translate> This function takes an input string, interprets it as a page title, and returns one of two values depending on whether or not the page exists on the local wiki.</translate>

{{#ifexist: page title | value if exists | value if doesn't exist }}

<translate> The function evaluates to true if the page exists, whether it contains content, is visibly blank (contains meta-data such as category links or {{<tvar|help-magic>mediawiki|Special:MyLanguage/Help:Magic words</>|magic words}}, but no visible content), is blank, or is a {{<tvar|help-redirects>mediawiki|Special:MyLanguage/Help:Redirects</>|redirect}}. Only pages that are redlinked evaluate to false, including if the page used to exist but has been deleted.</translate>

{{#ifexist: Help:Extension:ParserFunctions | exists | doesn't exist }}exists
{{#ifexist: XXHelp:Extension:ParserFunctionsXX | exists | doesn't exist }}doesn't exist

<translate> The function evaluates to true for {{<tvar|system>mediawiki|Special:MyLanguage/Help:System message</>|system messages}} that have been customized, and for {{<tvar|special>mediawiki|Special:MyLanguage/Help:Special pages</>|special pages}} that are defined by the software. </translate>

{{#ifexist: Special:Watchlist | exists | doesn't exist }}exists
{{#ifexist: Special:CheckUser | exists | doesn't exist }}doesn't exist <translate>

(because the CheckUser extension is not installed on this wiki)</translate>

{{#ifexist: MediaWiki:Copyright | exists | doesn't exist }}doesn't exist <translate>

(because MediaWiki:Copyright has not been customized)</translate>

<translate> If a page checks a target using <tvar|ifexist>#ifexist:</>, then that page will appear in the <tvar|spec-wth>Special:WhatLinksHere</> list for the target page. So if the code <tvar|code1>{{#ifexist</>:Foo <tvar|code2>}}</> were included live on this page (<tvar|fullpagename1>Help:Extension:ParserFunctions</>), [[<tvar|wth>Special:WhatLinksHere</>/Foo]] will list <tvar|fullpagename2>Help:Extension:ParserFunctions</>.

On wikis using a shared media repository, <tvar|ifexist>#ifexist:</> can be used to check if a file has been uploaded to the repository but not to the wiki itself:</translate>

{{#ifexist: File:Example.png | exists | doesn't exist }}doesn't exist
{{#ifexist: Image:Example.png | exists | doesn't exist }}doesn't exist
{{#ifexist: Media:Example.png | exists | doesn't exist }}doesn't exist

<translate> If a local description page has been created for the file, the result is exists for all of the above.

<tvar|ifexist>#ifexist:</> does not work with interwiki links.

ifexist limits

<tvar|ifexist>#ifexist:</> is considered an "expensive parser function"; only a limited number of which can be included on any one page (including functions inside transcluded templates). When this limit is exceeded, any further <tvar|ifexist>#ifexist:</> functions automatically return false, whether the target page exists or not, and the page is categorized into <tvar|category>Category:Pages with too many expensive parser function calls</>. The name of the {{<tvar|tracking>mediawiki|Special:MyLanguage/Help:Tracking categories</>|tracking category}} may vary depending on the content language of your wiki.

For some use cases it is possible to emulate the ifexist effect with css, by using the selectors a.new (to select links to unexisting pages) or a:not(.new) (to select links to existing pages). Furthermore, since the number of expensive parser functions that can be used on a single page is controlled by <tvar|ExpensiveParserFunctionsLimit>$wgExpensiveParserFunctionLimit</>, one can also increase the limit in LocalSettings.php if needed. </translate>

#rel2abs

<translate> This function converts a relative file path into an absolute filepath.

<tvar|code1>{{#rel2abs:</> path <tvar|code2>}}</>
<tvar|code3>{{#rel2abs:</> path <tvar|code4>|</> base path <tvar|code5>}}</>

Within the path input, the following syntax is valid:

  • <tvar|code1>.</> → the current level
  • <tvar|code2>..</> → "go up one level"
  • <tvar|code3></>/foo <tvar|code4></> → "go down one level into the subdirectory /foo"

If the <tvar|code1></> base path <tvar|code2></> is not specified, the full page name of the page will be used instead:

<tvar|code1>{{#rel2abs:</> /quok <tvar|code2>| Help</>:Foo/bar/baz <tvar|code3>}}</> /quok <tvar</>
<tvar|code11>{{#rel2abs: .</>/quok <tvar|code12>| Help</>:Foo/bar/baz <tvar|code13>}}.</>/quok <tvar</>
<tvar|code21>{{#rel2abs: ..</>/quok <tvar|code22>| Help</>:Foo/bar/baz <tvar|code23>}}..</>/quok <tvar</>
<tvar|code31>{{#rel2abs: ..</>/. <tvar|code32>| Help</>:Foo/bar/baz <tvar|code33>}}..</>/. <tvar</>

Invalid syntax, such as <tvar|code1>/.</> or <tvar|code2>/./</>, is ignored. Since no more than two consecutive full stops are permitted, sequences such as these can be used to separate successive statements:

<tvar|code1>{{#rel2abs: ..</>/quok/. <tvar|code2>| Help</>:Foo/bar/baz <tvar|code3>}}..</>/quok/. <tvar</>
<tvar|code11>{{#rel2abs: ../..</>/quok <tvar|code12>| Help</>:Foo/bar/baz <tvar|code13>}}..</>/quok <tvar</>
<tvar|code21>{{#rel2abs: ../../..</>/quok <tvar|code22>| Help</>:Foo/bar/baz <tvar|code23>}}Error: Invalid depth in path: "code24>/../../..</>/quok <tvar" (tried to access a node above the root node).</>
<tvar|code31>{{#rel2abs: ../../../..</>/quok <tvar|code32>| Help</>:Foo/bar/baz <tvar|code33>}}Error: Invalid depth in path: "code34>/../../../..</>/quok <tvar" (tried to access a node above the root node).</>

</translate>

#switch

<translate> This function compares one input value against several test cases, returning an associated string if a match is found.</translate>

{{#switch: comparison string
 | case = result
 | case = result
 | ...
 | case = result
 | default result
}}

<translate> Examples:</translate>

{{#switch: baz | foo = Foo | baz = Baz | Bar }} Baz
{{#switch: foo | foo = Foo | baz = Baz | Bar }} Foo
{{#switch: zzz | foo = Foo | baz = Baz | Bar }} Bar

<translate> <tvar|switch>#switch</> with partial transclusion tags can effect a configuration file that enables an editor unfamiliar with template coding to view and edit configurable elements.</translate> <translate>

Default

The default result is returned if no case string matches the comparison string: </translate>

{{#switch: test | foo = Foo | baz = Baz | Bar }} Bar

<translate> In this syntax, the default result must be the last parameter and must not contain a raw equals sign.</translate>

{{#switch: test | Bar | foo = Foo | baz = Baz }} →
{{#switch: test | foo = Foo | baz = Baz | B=ar }} →

<translate> Alternatively, the default result may be explicitly declared with a case string of "#default".</translate>

{{#switch: comparison string
 | case = result
 | case = result
 | ...
 | case = result
 | #default = default result
}}

<translate> Default results declared in this way may be placed anywhere within the function:</translate>

{{#switch: test | foo = Foo | #default = Bar | baz = Baz }} Bar

<translate> If the default parameter is omitted and no match is made, no result is returned:</translate>

{{#switch: test | foo = Foo | baz = Baz }}

<translate>

Grouping results

It is possible to have 'fall through' values, where several case strings return the same result string. This minimizes duplication. </translate>

{{#switch: comparison string
 | case1 = result1
 | case2 
 | case3 
 | case4 = result234
 | case5 = result5
 | case6 
 | case7 = result67
 | #default = default result
}}

<translate> Here cases 2, 3 and 4 all return result234; cases 6 and 7 both return result67

Comparison behavior

As with <tvar|ifeq>#ifeq</>, the comparison is made numerically if both the comparison string and the case string being tested are numeric; or as a case-sensitive string otherwise:</translate>

{{#switch: 0 + 1 | 1 = one | 2 = two | three}} → three
{{#switch: {{#expr: 0 + 1}} | 1 = one | 2 = two | three}} → one
{{#switch: a | a = A | b = B | C}} → A
{{#switch: A | a = A | b = B | C}} → C

<translate> A case string may be empty:</translate>

{{#switch: | = Nothing | foo = Foo | Something }}Nothing

<translate> Once a match is found, subsequent cases are ignored:</translate>

{{#switch: b | f = Foo | b = Bar | b = Baz | }}Bar

{{ Script error: No such module "Template translation". |<translate> Numerical comparisons with <tvar|switch>#switch</> and <tvar|ifeq>#ifeq</> are not equivalent with comparisons in expressions (see also above):</translate>

{{#switch: 12345678901234567 | 12345678901234568 = A | B}} → B
{{#ifexpr: 12345678901234567 = 12345678901234568 | A | B}} → A

}}

<translate>

Raw equal signs

"Case" strings cannot contain raw equals signs. To work around this, create a template <tvar|tpl>{{=}}</> containing a single equals sign: <tvar|code1>=</>, or replace equals sign to html code <tvar|code2>&#61;</>.

Example:</translate>

{{#switch: 1=2
 | 1=2 = raw
 | 1<nowiki>=</nowiki>2 = nowiki
 | 1{{=}}2 = template
 | default
}}template


{{#switch: 1=2
 | 1&#61;2 = html
 | default
}}html

{{ Script error: No such module "Template translation".

 |1=
 |2=
 |demo=
 }}

<translate> For a simple real life example of the use of this function, check [<tvar|enwp-nba-color>https://en.wikipedia.org/w/index.php?title=Template:NBA_color&action=edit&oldid=600531646</> Template:NBA color]. Two complex examples can be found at <tvar|tpl-ext>Template:Extension</> and [<tvar|enwp-botreq>http://en.wikipedia.org/wiki/Template:BOTREQ</> Template:BOTREQ].

Replacing #ifeq

#switch can be used to reduce expansion depth.

For example:</translate>

  • {{#switch:{{{1}}} |condition1=branch1 |condition2=branch2 |condition3=branch3 |branch4}}

<translate> is equivalent to</translate>

  • {{#ifeq:{{{1}}}|condition1 |branch1 |{{#ifeq:{{{1}}}|condition2 |branch2 |{{#ifeq:{{{1}}}|condition3 |branch3 |branch4}}}}}}

i.e. deep nesting, linear:

{{#ifeq:{{{1}}}|condition1
  |<!--then-->branch1
  |<!--else-->{{#ifeq:{{{1}}}|condition2
                |<!--then-->branch2
                |<!--else-->{{#ifeq:{{{1}}}|condition3
                              |<!--then-->branch3
                              |<!--else-->branch4}}}}}}

On the other hand, the switch replacement could be complicated/impractical for IFs nested in both branches (shown with alternatives of indentation, indented on both sides), making full symmetrical tree:

{{#ifeq:{{{1}}}|condition1
 |<!--then-->branch1t{{
  #ifeq:{{{1}}}|condition2
   |<!--then-->branch1t2t{{#ifeq:{{{1}}}|condition4|<!--then-->branch1t2t4t|<!--else-->branch1t2t4e}}
   |<!--else-->branch1t2e{{#ifeq:{{{1}}}|condition5|<!--then-->branch1t2e5t|<!--else-->branch1t2e5e}}
  }}
 |<!--else-->branch1e{{#ifeq:{{{1}}}|condition3
   |<!--then-->branch1e3t{{#ifeq:{{{1}}}|condition6|branch1e3t6t|branch1e3t6e}}
   |<!--else-->branch1e3e{{
    #ifeq:{{{1}}}|condition7
     |branch1e3e7t
     |branch1e3e7t
    }}
  }}
}}

#time

<translate> Code</translate> <translate> Description</translate> <translate>

Current output
([{<tvar|fullurl>{fullurl:Help:Extension:ParserFunctions{{#translation:}}|action=purge}}</> Purge this page's cache] to update)</translate>

<translate> Year</translate>
Y <translate> 4-digit year.</translate> 2025
y <translate> 2-digit year.</translate> 25
L <translate> 1 if it's a leap year, 0 if not.</translate> 0
o<ref group="note"><translate>

Requires PHP 5.1.0 and newer and rev:45208.</translate></ref>

<translate>

ISO-8601 year of the specified week.</translate><ref group="note"><translate> This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.</translate></ref>

2025<ref group="note"><translate>

Will output literal o if note 1 not fulfilled.</translate></ref>

<references group="note"/>

<translate> Month</translate>
n <translate> Month index, not zero-padded.</translate> 3
m <translate> Month index, zero-padded.</translate> 03
M <translate> An abbreviation of the month name, in the site language.</translate> Mar
F <translate> The full month name in the site language.</translate> March
xg <translate>

Output the full month name in the genitive form for site languages that distinguish between genitive and nominative forms. This option is useful for many Slavic languages like Polish, Russian, Belarusian, Czech, Slovak, Slovene, Ukrainian, etc.</translate>

<translate>

For Polish:</translate>
{{#time:F Y|June 2010|pl}} → czerwiec 2010
<translate> (nominative)</translate>
{{#time:d xg Y|20 June 2010|pl}} → 20 czerwca 2010
<translate>

(genitive)</translate>
<translate> Day of the month or the year</translate>
j <translate> Day of the month, not zero-padded.</translate> 16
d <translate> Day of the month, zero-padded.</translate> 16
z <translate> Day of the year (January 1 = 0).
{{ Script error: No such module "Template translation".
1= 2= demo=
 }} To get the ISO day of the year add 1.</translate>
74
<translate> Week and day of the week</translate>
W <translate> ISO 8601 week number, zero-padded.</translate> 11
N <translate> ISO 8601 day of the week (Monday = 1, Sunday = 7).</translate> 7
w <translate> Number of the day of the week (Sunday = 0, Saturday = 6).</translate> 0
D <translate> An abbreviation for the day of the week. Rarely internationalized.</translate> Sun
l <translate> The full weekday name. Rarely internationalized.</translate> Sunday
<translate> Hour</translate>
a <translate> "am" during the morning (00:00:00 → 11:59:59), "pm" otherwise (12:00:00 → 23:59:59).</translate> am
A <translate> Uppercase version of a above.</translate> AM
g <translate> Hour in 12-hour format, not zero-padded.</translate> 6
h <translate> Hour in 12-hour format, zero-padded.</translate> 06
G <translate> Hour in 24-hour format, not zero-padded.</translate> 6
H <translate> Hour in 24-hour format, zero-padded.</translate> 06
<translate> Minutes and seconds</translate>
i <translate> Minutes past the hour, zero-padded.</translate> 36
s <translate> Seconds past the minute, zero-padded.</translate> 41
U <translate> Unix time.</translate> <translate> Seconds since January 1 1970 00:00:00 GMT.</translate> 1742107001
<translate> Timezone (as of 1.22wmf2)</translate>
e <translate> Timezone identifier.</translate> UTC
I <translate> Whether or not the date is in daylight savings time.</translate> 0
O <translate> Difference to Greenwich time (GMT)</translate> +0000
P <translate> Difference to Greenwich time (GMT), with colon</translate> +00:00
T <translate> Timezone abbreviation.</translate> UTC
Z <translate> Timezone offset in seconds.</translate> 0
<translate> Miscellaneous</translate>
t <translate> Number of days in the current month.</translate> 31
c iso8601>Y-m-d"T"H:i:s+00:00</>.</translate> 2025-03-16T06:36:41+00:00
r <translate> RFC 5322 formatted date, equivalent to <tvar|rfc5322>D, j M Y H:i:s +0000</>, with weekday name and month name not internationalized.</translate> Sun, 16 Mar 2025 06:36:41 +0000
<translate> Non-Gregorian calendars</translate>
<translate> Islamic</translate>
xmj <translate> Day of the month.</translate> 16
xmF <translate> Full month name.</translate> Ramadan
xmn <translate> Month index.</translate> 9
xmY <translate> Full year.</translate> 1446
<translate> Iranian (Jalaly)</translate>
xit <translate> Number of days in the month.</translate> 29
xiz <translate> Day of the year.</translate> 361
xij <translate> Day of the month.</translate> 26
xiF <translate> Full month name.</translate> Esfand
xin <translate> Month index.</translate> 12
xiY <translate> Full year.</translate> 1403
xiy <translate> 2-digit year.</translate> 03
<translate> Hebrew</translate>
xjj <translate> Day of the month.</translate> 16
xjF <translate> Full month name.</translate> Adar
xjt <translate> Number of days in month.</translate> 29
xjx <translate> Genitive form of the month name.</translate> Adar
xjn <translate> Month number.</translate> 6
xjY <translate> Full year.</translate> 5785
<translate> Thai solar</translate>
xkY <translate> Full year in Thai solar calendar.
Script error: No such module "Template translation". For years before 1941 the dates in Jan-Mar range are not calculated properly.</translate>
2568
<translate> Minguo/Juche year</translate>
xoY <translate> Full year.</translate> 114
<translate> Japanese nengo</translate>
xtY <translate> Full year.</translate> 令和7
<translate> Flags</translate>
xn <translate> Format the next numeric code as a raw ASCII number.</translate> time>{{#time:H, xnH}}</> produces <tvar|hindi>०६, 06</>.</translate>
xN <translate> Like xn, but as a toggled flag, which endures until the end of the string or until the next appearance of xN in the string.</translate>
xr <translate> Format the next number as a roman numeral. Only works for numbers up to 10,000
(upto 3,000 in pre MediaWiki 1.20).</translate>
{{#time:xrY}} → MMXXV
xh <translate> Format the next number as a Hebrew numeral.</translate> {{#time:xhY}} → ב'כ"ה

<translate> This parser function takes a date and/or time (in the Gregorian calendar) and formats it according to the syntax given. A date/time object can be specified; the default is the value of the [[<tvar|magic>Special:MyLanguage/Help:Magic words#Date and time</>|magic word]] <tvar|currenttimestamp>{{CURRENTTIMESTAMP}}</> – that is, the time the page was last rendered into HTML.</translate>

{{#time: format string }}
{{#time: format string | date/time object }}
{{#time: format string | date/time object | language code }}

<translate> The list of accepted formatting codes is given in the table to the right. Any character in the formatting string that is not recognized is passed through unaltered; this applies also to blank spaces (the system does not need them for interpreting the codes). There are also two ways to escape characters within the formatting string:

  1. A backslash followed by a formatting character is interpreted as a single literal character
  2. Characters enclosed in double quotes are considered literal characters, and the quotes are removed.

In addition, the digraph xx is interpreted as a single literal "x".</translate>

{{#time: Y-m-d }}2025-03-16
{{#time: [[Y]] m d }}2025 03 16
{{#time: [[Y (year)]] }}2025 (25UTCamSun, 16 Mar 2025 06:36:41 +0000)
{{#time: [[Y "(year)"]] }}2025 (year)
{{#time: i's" }}36'41"

<translate> The date/time object can be in any format accepted by PHP's strtotime() function. Both absolute (eg 20 December 2000) and relative (eg +20 hours) times are accepted.</translate>

{{#time: r|now}}Sun, 16 Mar 2025 06:36:43 +0000
{{#time: r|+2 hours}}Sun, 16 Mar 2025 08:36:43 +0000
{{#time: r|now + 2 hours}}Sun, 16 Mar 2025 08:36:43 +0000
{{#time: r|20 December 2000}}Wed, 20 Dec 2000 00:00:00 +0000
{{#time: r|December 20, 2000}}Wed, 20 Dec 2000 00:00:00 +0000
{{#time: r|2000-12-20}}Wed, 20 Dec 2000 00:00:00 +0000
{{#time: r|2000 December 20}}Error: Invalid time.

<translate> The language code in ISO 639-3 (?) allows the string to be displayed in the chosen language</translate>

{{#time:d F Y|1988-02-28|nl}}28 februari 1988
{{#time:l|now|uk}}неділя
{{#time:d xg Y|20 June 2010|pl}}20 czerwca 2010

<translate> If you've calculated a Unix timestamp, you may use it in date calculations by pre-pending an @ symbol.</translate>

{{#time: U | now }}1742107003
{{#time: r | @1742107001 }}Sun, 16 Mar 2025 06:36:41 +0000

{{ Script error: No such module "Template translation". |1=<translate>Without the @ prefix before numeric timestamp values, the result is an error most of the time, or is an unexpected value:</translate>

{{#time: r | 1970-01-01 00:16:39 }}Thu, 01 Jan 1970 00:16:39 +0000
{{#time: U | 1970-01-01 00:16:39 }}999
{{#time: r | @999 }}Thu, 01 Jan 1970 00:16:39 +0000 <translate>(correct)</translate>
{{#time: r | 999 }}Error: Invalid time. <translate>(unsupported year format)</translate>
{{#time: r | 1970-01-01 00:16:40 }}Thu, 01 Jan 1970 00:16:40 +0000
{{#time: U | 1970-01-01 00:16:40 }}1000
{{#time: r | @1000 }}Thu, 01 Jan 1970 00:16:40 +0000 <translate>(correct)</translate>
{{#time: r | 1000 }}Sun, 16 Mar 1000 00:00:00 +0000 <translate>(interpreted as a year with current month and day of the month)</translate>
{{#time: r | 1970-01-01 02:46:39 }}Thu, 01 Jan 1970 02:46:39 +0000
{{#time: U | 1970-01-01 02:46:39 }}9999
{{#time: r | @9999 }}Thu, 01 Jan 1970 02:46:39 +0000 <translate>(correct)</translate>
{{#time: r | 9999 }}Tue, 16 Mar 9999 00:00:00 +0000 <translate>(interpreted as a year with current month and day of the month)</translate>
{{#time: r | 1970-01-01 02:46:40 }}Thu, 01 Jan 1970 02:46:40 +0000
{{#time: U | 1970-01-01 02:46:40 }}10000
{{#time: r | @10000 }}Thu, 01 Jan 1970 02:46:40 +0000 <translate>(correct)</translate>
{{#time: r | 10000 }}Error: Invalid time. <translate>(unsupported year format)</translate>

}}

{{ Script error: No such module "Template translation". |<translate> The range of acceptable input is 1 January 0111 → 31 December 9999. For the years 100 through 110 the output is inconsistent, Y and leap years are like the years 100-110, r, D, l and U are like interpreting these years as 2000-2010.</translate>
{{#time: d F Y | 29 Feb 0100 }}01 March 0100
<translate> (correct, no leap year), but</translate>
{{#time: r | 29 Feb 0100 }}Mon, 01 Mar 0100 00:00:00 +0000 <translate> (wrong, even if 100 is interpreted as 2000, because that is a leap year)</translate>
{{#time: d F Y | 15 April 10000 }}Error: Invalid time.
{{#time: r | 10000-4-15 }}Sat, 15 Apr 2000 10:00:00 +0000

<translate> Year numbers 0-99 are interpreted as 2000-2069 and 1970-1999, except when written in 4-digit format with leading zeros:</translate>
{{#time: d F Y | 1 Jan 6 }}01 January 2006
{{#time: d F Y | 1 Jan 06 }}01 January 2006
{{#time: d F Y | 1 Jan 006 }}01 January 2006
{{#time: d F Y | 1 Jan 0006 }}01 January 0006 (4-digit format)

<translate> The weekday is supplied for the years 100-110 and from 1753, for the years 111-1752 the r-output shows "Unknown" and the l-output "<>". As a consequence, the r-output is not accepted as input for these years.</translate>}}

<translate> Full or partial absolute dates can be specified; the function will "fill in" parts of the date that are not specified using the current values:</translate>

{{#time: Y | January 1 }}2025

{{ Script error: No such module "Template translation". |<translate> The fill-in feature is not consistent; some parts are filled in using the current values, others are not:</translate>
{{#time: Y m d H:i:s | June }}2025 06 16 00:00:00 <translate> Gives the start of the day, but the current day of the month and the current year.</translate> {{#time: Y m d H:i:s | 2003 }}2003 03 16 00:00:00 <translate> Gives the start of the day, but the current day of the year.</translate> }}

<translate> A four-digit number is always interpreted as a year, never as hours and minutes:<ref>Prior to Template:Rev in 2011 this was not the case.</ref></translate>

{{#time: Y m d H:i:s | 1959 }}1959 03 16 00:00:00

<translate> A six-digit number is interpreted as hours, minutes and seconds if possible, but otherwise as an error (not, for instance, a year and month):</translate>

{{#time: Y m d H:i:s | 195909 }}2025 03 16 19:59:09 <translate>

Input is treated as a time rather than a year+month code.</translate>

{{#time: Y m d H:i:s | 196009 }}Error: Invalid time. <translate>

Although 19:60:09 is not a valid time, 196009 is not interpreted as September 1960.</translate>

<translate> The function performs a certain amount of date mathematics:</translate>

{{#time: d F Y | January 0 2008 }}31 December 2007
{{#time: d F | January 32 }}Error: Invalid time.
{{#time: d F | February 29 2008 }}29 February
{{#time: d F | February 29 2007 }}01 March
{{#time:Y-F|now -1 months}}2025-February

<translate> The total length of the format strings of the calls of <tvar|time>#time</> is limited to 6000 characters<ref>ParserFunctions_body.php at phabricator.wikimedia.org</ref>.

Time Zone issue

There is a bug in this #time parser function (more specifically in PHP DateTime) that does not allow the passing-in of non-integers as relative time zone offsets. This issue does not apply when using an on-the-hour time zone, such as EDT. For example:</translate>

  • {{#time:g:i A | -4 hours }} ==> 2:36 AM

<translate> However, Venezuela is on a -4.5 hours time offset from UTC, and thus using its time zone will not normally allow the correct calculation of a relative time zone offset. Here's what happens:</translate>

  • {{#time:g:i A | -4.5 hours }} ==> 3:36 PM

<translate> To workaround this issue, simply convert the time into minutes or seconds, like this:</translate>

  • {{#time:g:i A | -270 minutes }} ==> 2:06 AM
  • {{#time:g:i A | -16200 seconds }} ==> 2:06 AM

<translate> (Tim Starling, the developer of this function, provided the exact syntax for this solution.)</translate>

#timel

<translate> This function is identical to <tvar|time>{{#time: ... }}</>, except that it uses the local time of the wiki (as set in $wgLocaltimezone) when no date is given.</translate>

{{#time: Y-m-d }}2025-03-16
{{#timel: Y-m-d }}2025-03-16
{{#time: Y F d H:i:s}}2025 March 16 06:36:41
{{#timel: Y F d H:i:s}}2025 March 16 06:36:41
File:Maldiskusjon Sommertid–Wikipedia.jpg
no-wp>https://no.wikipedia.org/wiki/Maldiskusjon:Sommertid</></translate>

{{ Script error: No such module "Template translation". |<translate> Be aware that U for both time and timel will return the same number of seconds since 1970-01-01 00:00:00 UTC on Wikipedias with different timezones than UTC (formerly known as GMT)</translate>

U <translate> Unix time. Seconds since January 1 1970 00:00:00 GMT.</translate>
Z <translate> Timezone offset in seconds.</translate>
{{#time: U}}1742107001
{{#timel: U}}1742107001
{{#time: Z}}0
{{#timel: Z}}0

}}

#titleparts

<translate> This function separates a page title into segments based on slashes, then returns some of those segments as output.</translate>

<translate> <tvar|code0>{{#titleparts:</> pagename <tvar|code1>|</> number of segments to return <tvar|code2>|</> first segment to return <tvar|code3>}}</></translate>

<translate> If the number of segments to return parameter is not specified, it defaults to "0", which returns all the segments from the first segment to return (included). If the first segment to return parameter is not specified or is "0", it defaults to "1":</translate>

{{#titleparts: Talk:Foo/bar/baz/quok }}Talk:Foo/bar/baz/quok
{{#titleparts: Talk:Foo/bar/baz/quok | 1 }}Talk:Foo See also {{ROOTPAGENAMEHelp:Magic_words#Page_names}}.
{{#titleparts: Talk:Foo/bar/baz/quok | 2 }}Talk:Foo/bar
{{#titleparts: Talk:Foo/bar/baz/quok | 2 | 2 }}bar/baz
{{#titleparts: Talk:Foo/bar/baz/quok | | 2 }}bar/baz/quok
{{#titleparts: Talk:Foo/bar/baz/quok | | 5 }}

<translate> Negative values are accepted for both values. Negative values for the number of segments to return parameter effectively 'strips' segments from the end of the string. Negative values for the first segment to return translates to "start with this segment counting from the right":</translate>

{{#titleparts: Talk:Foo/bar/baz/quok | -1 }}Talk:Foo/bar/baz <translate> Strips one segment from the end of the string. See also {{BASEPAGENAME}}.</translate>
{{#titleparts: Talk:Foo/bar/baz/quok | -4 }} <translate> Strips all 4 segments from the end of the string</translate>
{{#titleparts: Talk:Foo/bar/baz/quok | -5 }} <translate> Strips 5 segments from the end of the string (more than exist)</translate>
{{#titleparts: Talk:Foo/bar/baz/quok | | -1 }} quok <translate> Returns last segment. See also {{SUBPAGENAME}}.</translate>
{{#titleparts: Talk:Foo/bar/baz/quok | -1 | 2 }} bar/baz <translate> Strips one segment from the end of the string, then returns the second segment and beyond</translate>
{{#titleparts: Talk:Foo/bar/baz/quok | -1 | -2 }} baz <translate> Start copying at the second last element; strip one segment from the end of the string</translate>

<translate> Before processing, the pagename parameter is HTML-decoded: if it contains some standard HTML character entities, they will be converted to plain characters (internally encoded with UTF-8, i.e. the same encoding as in the MediaWiki source page using this parser function).</translate>

<translate> For example, any occurence of <tvar|q1>&quot;</>, <tvar|q2>&#34;</>, or <tvar|q3>&#x22;</> in pagename will be replaced by <tvar|q>"</>.</translate>
<translate> No other conversion from HTML to plain text is performed, so HTML tags are left intact at this initial step even if they are invalid in page titles.</translate>

{{ Script error: No such module "Template translation".

 |1=PAGENAME>{{PAGENAMEHelp:Magic words#Page names}}</> and similar) are known to return strings that are needlessly HTML-encoded, even if their own input parameter was not HTML-encoded:</translate>

<translate> The titleparts parser function can then be used as a workaround, to convert these returned strings so that they can be processed correctly by some other parser functions also taking a page name in parameter (such as <tvar

 |2=reminder
 |demo=
 }}

<translate> Then the decoded pagename is canonicalized into a standard page title supported by MediaWiki, as much as possible:</translate>

  1. <translate> All underscores are automatically replaced with spaces:</translate>
    {{#titleparts: Talk:Foo/bah_boo|1|2}}bah boo <translate> Not bah_boo, despite the underscore in the original.</translate>
  2. <translate> The string is split a maximum of 25 times; further slashes are ignored and the 25th element will contain the rest of the string. The string is also limited to 255 characters, as it is treated as a page title:</translate>
    {{#titleparts: a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/aa/bb/cc/dd/ee | 1 | 25 }}y/z/aa/bb/cc/dd/ee
    <translate> If for whatever reason you needed to push this function to its limit, although very unlikely, it is possible to bypass the 25 split limit by nesting function calls:</translate>
    {{#titleparts: {{#titleparts: a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/aa/bb/cc/dd/ee| 1 | 25 }} | 1 | 2}}z
  3. <translate> Finally the first substring is capitalized according to the capitalization settings of the local wiki (if that substring also starts by a local namespace name, that namespace name is also normalized).</translate>
    {{#titleparts: talk:a/b/c }}Talk:A/b/c

{{ Script error: No such module "Template translation".| 1 = <translate> You can use #titleparts as a small "string parser and converter", but consider that it returns the first substring capitalized:</translate>

{{#titleparts: one/two/three/four|1|1 }}One
{{#titleparts: one/two/three/four|1|2 }}two

<translate> If lower case is needed, use lc: function to control output:</translate>

{{lc: {{#titleparts: one/two/three/four|1|1 }} }}one

<translate> You can prepend a 'dummy' slash at the beginning of the string to get the correct first substring capitalization (uppercase or lowercase). Use <tvar|2>2</> instead of <tvar|p1>1</> for first segment to return:</translate>

{{#titleparts: /one/two/three/four|1|2 }}one
{{#titleparts: /One/two/three/four|1|2 }}One

}}

{{ Script error: No such module "Template translation".| 1 = <translate> Certain characters that are illegal in a page title will cause #titleparts to not parse the string:</translate>

{{#titleparts: {one/two} | 1 | 1 }}{one/two}. <translate> Does not produce the expected:</translate> {one
{{#titleparts: [[page]]/123 | 1 | 2 }}page/123. <translate> Does not work because brackets are illegal in page titles and this parser function does not process links embedded in its input pagename parameter, even when they use the MediaWiki syntax, or any other HTML or MediaWiki tags.</translate>
{{#titleparts: red/#00FF00/blue | 1 | 3 }} → "". <translate> Does not work because "#" is also illegal in page titles.</translate>

}}

{{ Script error: No such module "Template translation".| 1 = <translate> If any part of the title is just "." or "..", #titleparts will not parse the string:</translate>

{{#titleparts: one/./three | 1 | 1 }}one/./three. <translate> The whole string is returned. It does not produce the expected:</translate> one

}}

{{ Script error: No such module "Template translation".| 1 = <translate> This function does not degrade gracefully if your input exceeds 255 characters. If the inputted string is 256 characters long or more, this function will simply toss the string back at you.</translate> }}

<translate>

General points

Substitution

Parser functions can be substituted by prefixing the hash character with <tvar|subst>subst:</>:</translate>

{{subst:#ifexist: Help:Extension:ParserFunctions | [[Help:Extension:ParserFunctions]] | Help:Extension:ParserFunctions }} → <translate>

the code [[Help:Extension:ParserFunctions]] will be inserted in the wikitext since the page Help:Extension:ParserFunctions exists.</translate>

{{ Script error: No such module "Template translation". |<translate> The results of substituted parser functions are undefined if the expressions contain unsubstituted volatile code such as {{<tvar|magic>mediawiki|Special:MyLanguage/Help:Magic words#Variables</>|variables}} or other parser functions. For consistent results, all the volatile code in the expression to be evaluated must be substituted. See Help:Substitution.</translate>}}

<translate> Substitution does not work within <tvar|code1><ref></ref></>, you can use <tvar|code2>{{subst:#tag:ref|}}</> for this purpose.

Redirects

Especially <tvar|time>{{#time:…|now-…}}</> could be handy in {{<tvar|redirects>mediawiki|Special:MyLanguage/Help:Redirects</>|redirects}} to pages including dates, but this does not work.

Escaping pipe characters in tables

Parser functions will mangle {{<tvar|help-tables>mediawiki|Special:MyLanguage/Help:Tables</>|wikitable}} syntax and pipe characters (<tvar|pipe>|</>), treating all the raw pipe characters as parameter dividers. To avoid this, most wikis used a template <tvar|template>Template:!</> with its contents only a raw pipe character (<tvar|pipe>|</>), since MW 1.24 a {{<tvar|help-magic>mediawiki|Special:MyLanguage/Help:Magic words#Other|{{!}}</> magic word}} replaced this kludge. This 'hides' the pipe from the MediaWiki parser, ensuring that it is not considered until after all the templates and variables on a page have been expanded. It will then be interpreted as a table row or column separator. Alternatively, raw HTML table syntax can be used, although this is less intuitive and more error-prone.

You can also escape the pipe character for display as a plain, uninterpreted character using an HTML entity: <tvar|entity>&#124;</> .</translate>

<translate>

Description</translate>

<translate>

You type</translate>

<translate>

You get</translate>

<translate>

Escaping pipe character as table row/column separator</translate>

{{!}}
|
<translate>

Escaping pipe character as a plain character</translate>

&#124;
|

<translate>

Stripping whitespace

Whitespace, including newlines, tabs, and spaces, is stripped from the beginning and end of all the parameters of these parser functions. If this is not desirable, comparison of strings can be done after putting them in quotation marks.</translate>

{{#ifeq: foo           |           foo | equal | not equal }}equal
{{#ifeq: "foo          " | "          foo" | equal | not equal }}not equal

<translate> To prevent the trimming of then and else parts, see <tvar|meta-tpl-if>m:Template:If</>. Some people achieve this by using <{{<tvar|markup-nw>mediawiki|Special:MyLanguage/Wiki markup#Nowiki</>|nowiki}}> </nowiki> instead of spaces. </translate>

foo{{#if:|| bar }}foofoobarfoo
foo{{#if:||<nowiki /> bar <nowiki />}}foofoo bar foo

<translate> However, this method can be used to render a single whitespace character only, since the parser squeezes multiple whitespace characters in a row into one. </translate>

<span style="white-space: pre;">foo{{#if:||<nowiki></nowiki>      bar      <nowiki></nowiki>}}foo</span>foo bar foo

<translate> In this example, the white-space: pre style is used to force the whitespace to be preserved by the browser, but even with it the spaces are not shown. This happens because the spaces are stripped by the software, before being sent to the browser.

It is possible to workaround this behavior replacing whitespaces with &#32; (breakable space) or &nbsp; (non-breakable space), since they are not modified by the software: </translate>

<span style="white-space: pre;">foo{{#if:||&#32;&#32;&#32;bar&#32;&#32;&#32;}}foo</span>foo bar foo
foo{{#if:||&nbsp;&nbsp;&nbsp;bar&nbsp;&nbsp;&nbsp;}}foofoo   bar   foo

<translate>

See also

</translate>

<translate>

  • [[<tvar|mcalc>meta:Help:Calculation</>|Help:Calculation]] (on Meta)
  • {{<tvar|meta-newlines>Mediawiki|meta:Help:Newlines and spaces</>|Help:Newlines and spaces}} on Meta
  • {{<tvar|meta-compare>Mediawiki|meta:Help:Comparison between ParserFunctions syntax and TeX syntax</>|Help:Comparison between ParserFunctions syntax and TeX syntax}} on Meta

</translate>

<translate>

  • <tvar|module-string>Module:String</> obsoleting [[<tvar|ext-StringFunctions>Special:MyLanguage/Extension:StringFunctions</>|Extension:StringFunctions]]

</translate>

<translate>

References

</translate> Template:Reflist

[[Category:Extension help{{#translation:}}|ParserFunctions]] [[Category:Magic words{{#translation:}}]]