Help:ParserFunctions

From Homestar Runner Wiki

(Difference between revisions)
Jump to: navigation, search
(Backup)
(Finished. Ahh.)
Line 87: Line 87:
==#switch:==
==#switch:==
 +
 +
<tt>switch</tt> compares a string against many items, and shows a result if one is true. Syntax:
 +
<pre>
 +
{{#switch: <value>
 +
| <result 1> = <text if 1 is true>
 +
| <result 2> = <text if 2 is true>
 +
| <result 3> = <text if 3 is true>
 +
| <result 4> = <text if 4 is true>
 +
| #default = <default value if none are true>
 +
}}</pre>
 +
 +
"| <result n> = <text if n is true>"  can be repeated as many times as neccesary. However, "#default" can only be used once.
 +
 +
It is also possible to have "fall-through":
 +
<pre>
 +
{{#switch: <value>
 +
| <result 1>
 +
| <result 2>
 +
| <result 3> = <text if 1, 2, or 3 is true>
 +
| <result 4> = <text if 4 is true>
 +
| #default = <default value if none are true>
 +
}}</pre>
 +
<nowiki><result 1> and <result 2> do not have equal signs, and instead will use <result 3>'s text.</nowiki>
==#time:==
==#time:==
 +
 +
<tt>time</tt> is used for time and date formatting. It can be used to show the current time or day, or a set time or day in a certain format. Either way, here are the codes (following UTC):
 +
 +
{| width="100%" border="5" cellspacing="2" cellpadding="2" style="font-size:15px;text-align:center;"
 +
|- bgcolor="#FFFF00"
 +
! width="25%" | Code !! width="25%" | What it is !! width="25%" | Possible results !! width="25%" | Currently
 +
|-
 +
| Y || 4 digit year || 1970-2038 || {{#time: Y }}
 +
|-
 +
| y || 2 digit year || 00-99 || {{#time: y }}
 +
|-
 +
| n ||  Month number || 1-12 || {{#time: n }}
 +
|-
 +
| m || Month number, with leading 0 || 01-12 || {{#time: m }}
 +
|-
 +
| M || Month name, abbreviated || Jan-Dec || {{#time: M }}
 +
|-
 +
| F || Full month name || January-December || {{#time: F }}
 +
|-
 +
| W || Current week of the year || 1-52 or 53, depending on year || {{#time: W }}
 +
|-
 +
| j || Day of the month || 1-31 || {{#time: j }}
 +
|-
 +
| d || Day of the month, with leading 0 || 01-31 || {{#time: d }}
 +
|-
 +
| z || Day of the year || 1-364, 365 on a leap year || {{#time: z }}
 +
|-
 +
| D || Day of the week, abbreviated || Mon-Sun || {{#time: D }}
 +
|-
 +
| l || Full day of the week || Monday-Sunday || {{#time: l }}
 +
|-
 +
| N || ISO 8601 day of the week || 1 (Monday) - 7 (Sunday) || {{#time: N }}
 +
|-
 +
| w || American day of the week || 0 (Monday - 6 (Sunday) || {{#time: w }}
 +
|-
 +
| a ||  || am-pm || {{#time: a }}
 +
|-
 +
| A || Capital || AM-PM || {{#time: A }}
 +
|-
 +
| g || 12 hour format of the hour || 1-12 || {{#time: g }}
 +
|-
 +
| h || 12 hour format of the hour, with leading 0 || 01-12 || {{#time: h }}
 +
|-
 +
| G || 24 hour format of the hour || 0-23 || {{#time: G }}
 +
|-
 +
| H || 24 hour format of the hour, with leading 0 || 00-23 || {{#time: H }}
 +
|-
 +
| i || The minute || 00-59 || {{#time: i }}
 +
|-
 +
| s || The second || 00-59 || {{#time: s }}
 +
|-
 +
| U || Seconds since Midnight on  January 1, 1970|| 0-∞ || {{#time: U }}
 +
|-
 +
| L || Whether it's a leap year || 0 if not, 1 if yes || {{#time: L }}
 +
|-
 +
| t || Days in the month || 28-31 || {{#time: t }}
 +
|}
 +
Any text not shown above will come out unmodified, so links and punctuation are possible.
 +
Examples:
 +
*'''<nowiki>{{#time: l j F Y }}</nowiki>''' generates '''{{#time: l j F Y }}'''.
 +
*'''<nowiki>{{#time: m/Y }}</nowiki>''' generates '''{{#time: m/Y }}'''.
 +
*'''<nowiki>{{#time: H:i | - 6 hours}}</nowiki>''' generates '''{{#time: H:i | - 6 hours}}''', 6 hours before the current time
 +
*'''<nowiki>{{#time: l Y-m-d }}</nowiki>''' generates '''{{#time: l Y-m-d }}'''.
 +
*'''<nowiki>{{#time: l }}</nowiki>''' generates '''{{#time: l }}'''.
 +
*'''<nowiki>{{#time: z | 20071031}}</nowiki>''' generates '''{{#time: z | 20071031 }}''', Halloween day in "z" format
==#rand:==
==#rand:==
-
<tt>rand</tt> generated a random number. It has been depreciated in current versions of ParserFunctions, but the HRWiki uses an older version that still has rand. Syntax:
+
<tt>rand</tt> generates a random number. It has been depreciated in current versions of ParserFunctions, but the HRWiki uses an older version that still has rand. Syntax:
-
<pre>{{rand: <minimum> | <maximum> }}</pre>
+
<pre>{{#rand: <minimum> | <maximum> }}</pre>
The minimum is the smallest number it can generate, the maximum is the largest.  
The minimum is the smallest number it can generate, the maximum is the largest.  
Line 102: Line 190:
*'''<nowiki>{{#rand: 1 | 50 }}</nowiki>''' generates '''{{#rand: 1 | 50 }}'''.
*'''<nowiki>{{#rand: 1 | 50 }}</nowiki>''' generates '''{{#rand: 1 | 50 }}'''.
*'''<nowiki>{{#rand: 1 | 500000 }}</nowiki>''' generates '''{{#rand: 1 | 500000 }}'''.
*'''<nowiki>{{#rand: 1 | 500000 }}</nowiki>''' generates '''{{#rand: 1 | 500000 }}'''.
-
*'''<nowiki>{{#rand: .5 | 5.5 }}</nowiki>''' generates '''{{#rand: .5 | 5.5 }}'''.
+
*'''<nowiki>{{#rand: .1 | .9 }}</nowiki>''' generates '''{{#rand: .1 | .9 }}''', because it cannot do decimals.
[[Category:Help|{{PAGENAME}}]]
[[Category:Help|{{PAGENAME}}]]

Revision as of 00:44, 28 October 2007

This page is created as a future help page, before it goes into the Help namespace. If you have any ideas for this page, please tell me on the talk page.

This wiki has an extension installed, called ParserFunctions. Here's how to use them:

Contents

#expr:

expr solves mathematical expressions. It does not work with strings, if you want to use those, see ifeq. It also only works with numerical entries.

Operator Operation Example
() Grouping operators {{#expr: (10+20) / 30 }} = 0
+ Positive {{#expr: +30 - +30 }} = 0
- Negative {{#expr: -30 + 30 }} = 0
not Unary NOT, logical NOT {{#expr: not 30 + 0}} = 0
* Multiplication {{#expr: 30 * 0 }} = 0
/ OR div Division {{#expr: -30 / 30 }} = -1
{{#expr: -30 div 30 }} = -1
+ Addition {{#expr: -30 + 30 }} = 0
- Subtraction {{#expr: 30 - 30 }} = 0
round Rounds off the number on the left to the power of 1/10 given on the right {{#expr: 24 / 49 round 4}} = 0.4898
{{#expr: 24 / 49 round 2}} = 0.49
{{#expr: 24 / 49 round 0}} = 0
= Equality (will be 1 or 0) {{#expr: 30 = 0 }} = 0
{{#expr: 30 = 30 }} = 1
<> OR  != Inequality (will be 1 or 0) {{#expr: 30 <> 0 }} = 1
{{#expr: 30 <> 30 }} = 0
{{#expr: 30 != 0 }} = 1
{{#expr: 30 != 30 }} = 0
< Less Than (will be 1 or 0) {{#expr: 30 < 0 }} = 0
> Greater Than (will be 1 or 0) {{#expr: 30 > 0 }} = 1
>= Greater Than or Equal To (will be 1 or 0) {{#expr: 30 >= 0 }} = 1
<= Less Than or Equal To (will be 1 or 0) {{#expr: 30 <= 0 }} = 0

#if:

The if function is an if-then-else system. It measures if the condition string is empty, it does the else text. If it is not empty, it does the than text. The syntax is:

{{#if: <condition string> | <then text> | <else text> }}

Its most common usage is in templates, where if the user defines a parameter, then it shows this text. If the user does not specify it, it shows a default. Example:

{{#if: {{{parameter|}}} | Parameter is defined | Parameter is not defined }}

If the user types {{templatename|parameter=true}} or something similar, the result is "Parameter is defined". However, if they type {{templatename}}, the result it "Parameter is not defined".

This does not solve expressions. For example, if you type {{#if: 30 - 30 = 50 | 1 | 0 }}, the result will be 1, since 30 - 30 = 50 is not empty. If you want to do if-then-else using expressions, see #ifexpr.

#ifeq:

ifeq compares two strings and then does an then-else process. To use:

{{#ifeq: <text 1> | <text 2> | <if equal> | <if not equal> }}

If text 1 and text 2 are equal, then it does the <ifequal> text. Otherwise, it does the <ifnotequal> text.

Some examples:

  • {{#ifeq: {{NAMESPACE}} | Help | This page is in the Help Namespace | This page is not in the Help Namespace }} shows up as This page is in the Help Namespace.
  • {{#ifeq: 7 | +000007 | Seven = Seven | Seven is not equal to Seven }} shows up as Seven = Seven

ifeq is case-sensitive.

{{#ifeq: capital | Capital | Equal | Not Equal }} shows up as Not Equal.

#ifexist:

ifexist does an if-then-else process depending on if a page exists. Syntax:

{{#ifexist: <page name> | <if exists> | <if does not exist> }}

ifexist does not work with interwiki links.

Example:

{{#ifexist: sbemail | [[Strong Bad Email]] | [[Main Page]] }} gives Strong Bad Email because "sbemail" exists.

#ifexpr:

ifexpr is a combination of if-then-else and expr. It can only be done with numbers, just like expr. Syntax:

{{#ifexpr: <expression> | <if true> | <if false> }}

Some examples:

  • {{#ifexpr: 30 / 40 = 120 | yes | no }} shows up as no.
  • {{#ifexpr: {{PAGENAME}} = ParserFunctions | This is a help page | No}} shows up as Expression error: Unrecognised word "parserfunctions" because PAGENAME is not a number.

#switch:

switch compares a string against many items, and shows a result if one is true. Syntax:

{{#switch: <value>
| <result 1> = <text if 1 is true>
| <result 2> = <text if 2 is true>
| <result 3> = <text if 3 is true>
| <result 4> = <text if 4 is true>
| #default = <default value if none are true>
}}

"| <result n> = <text if n is true>" can be repeated as many times as neccesary. However, "#default" can only be used once.

It is also possible to have "fall-through":

{{#switch: <value>
| <result 1>
| <result 2>
| <result 3> = <text if 1, 2, or 3 is true>
| <result 4> = <text if 4 is true>
| #default = <default value if none are true>
}}

<result 1> and <result 2> do not have equal signs, and instead will use <result 3>'s text.

#time:

time is used for time and date formatting. It can be used to show the current time or day, or a set time or day in a certain format. Either way, here are the codes (following UTC):

Code What it is Possible results Currently
Y 4 digit year 1970-2038 2026
y 2 digit year 00-99 26
n Month number 1-12 6
m Month number, with leading 0 01-12 06
M Month name, abbreviated Jan-Dec Jun
F Full month name January-December June
W Current week of the year 1-52 or 53, depending on year 23
j Day of the month 1-31 5
d Day of the month, with leading 0 01-31 05
z Day of the year 1-364, 365 on a leap year 155
D Day of the week, abbreviated Mon-Sun Fri
l Full day of the week Monday-Sunday Friday
N ISO 8601 day of the week 1 (Monday) - 7 (Sunday) 5
w American day of the week 0 (Monday - 6 (Sunday) 5
a am-pm pm
A Capital AM-PM PM
g 12 hour format of the hour 1-12 11
h 12 hour format of the hour, with leading 0 01-12 11
G 24 hour format of the hour 0-23 23
H 24 hour format of the hour, with leading 0 00-23 23
i The minute 00-59 46
s The second 00-59 15
U Seconds since Midnight on January 1, 1970 0-∞ 1780703175
L Whether it's a leap year 0 if not, 1 if yes 0
t Days in the month 28-31 30

Any text not shown above will come out unmodified, so links and punctuation are possible. Examples:

  • {{#time: l j F Y }} generates Friday 5 June 2026.
  • {{#time: m/Y }} generates 06/2026.
  • {{#time: H:i | - 6 hours}} generates 17:46, 6 hours before the current time
  • {{#time: l Y-m-d }} generates Friday 2026-06-05.
  • {{#time: l }} generates Friday.
  • {{#time: z | 20071031}} generates 303, Halloween day in "z" format

#rand:

rand generates a random number. It has been depreciated in current versions of ParserFunctions, but the HRWiki uses an older version that still has rand. Syntax:

{{#rand: <minimum> | <maximum> }}

The minimum is the smallest number it can generate, the maximum is the largest.

Examples:

  • {{#rand: 1 | 50 }} generates 21.
  • {{#rand: 1 | 500000 }} generates 134831.
  • {{#rand: .1 | .9 }} generates 0, because it cannot do decimals.
Personal tools