Help:ParserFunctions: Difference between revisions
Content deleted Content added
→See also: rm deleted cat |
Happy-melon (talk | contribs) enough with not being able to edit sections |
||
Line 35:
===#expr:===
* syntax: {{ft|#expr|expression}}
Line 189:
|}
===#if:===
* syntax:
*: {{ft|#if|<nowiki><condition string> | <code if true></nowiki>}}
Line 203:
* {{ft|#if|<nowiki> | do if true | do if false</nowiki>}} = {{#if: | do if true | do if false}}
===#ifeq:===
* syntax:
*: {{ft|#ifeq|<nowiki><text 1> | <text 2> | <code if equal></nowiki>}}
Line 218:
* Text between <nowiki> tags is temporarily replaced by a unique code. This affects comparisons: {{ft|#ifeq|<nowiki><nowiki>abc</nowiki> | <nowiki>abc</nowiki> | equal | not equal</nowiki>}} returns "{{#ifeq:<nowiki>abc</nowiki> | <nowiki>abc</nowiki> | equal | not equal}}".
{{ft|#ifexist}} returns one of two results based on whether or not a particular page [[Help:Page existence|exists]].
Line 245:
:{{ft|#ifexist|<nowiki>Special:Nonsense|'''works'''|'''doesn't work'''</nowiki>}} gives {{#ifexist:Special:Nonsense|'''works'''|'''doesn't work'''}}
{{ft|#ifexpr}} evaluates a mathematical expression (see [[#.23expr:|#expr]]) and returns one of two strings depending on the result.
Line 271:
For another application, see also {{tim|evalns}}.
<code>switch</code> compares a single value against multiple others, returning a string if a match is found. The syntax is basically:
Line 347:
:{{ft|#ifeq|<nowiki>a | a | true | false </nowiki>}} gives {{#ifeq: a | a | true | false }}
===#time:===
{{ft|#time}} is a time and date formatting function. The syntax is:
Line 644:
Thus "-0300" and "-3" ''add'' 3 hours, while "-3 hours" subtracts them.
===#rel2abs:===
{{ft|#rel2abs}} converts a relative path to an absolute path.
Line 666 ⟶ 665:
:{{ft|#ifexist|{{ft sub|#rel2abs|.}}<nowiki> | '.' exist | '.' does not exist</nowiki>}} gives <tt>{{ #ifexist: {{#rel2abs: . }} | '.' exist | '.' does not exist }}</tt>
===#titleparts:===
'''<nowiki>{{</nowiki> #titleparts: ''pagename'' | ''n_of_segments'' | ''starting_from'' }}'''<br />
Line 694 ⟶ 692:
Introduced in [[rev:22711|r22711]], fixed to allow negative parameters in [[rev:28708|r28708]]. See also [[bugzilla:6067|bug 6067]].
===#iferror:===
<nowiki>{{#iferror</nowiki>:''expression''|''error''|''success''}} returns ''error'' if the expression contains a <nowiki><strong class="error"></nowiki> as generated by #expr, #ifexpr, #time, #rel2abs, and some other MediaWiki situations (such as recursive depth and template loop checks). This is most useful in catching bad input passed to such parserfunctions. For example:
|