Help:ParserFunctions
From Homestar Runner Wiki
The Goblin (Talk | contribs) (Done #if) |
The Goblin (Talk | contribs) (Backup) |
||
| Line 4: | Line 4: | ||
==#expr:== | ==#expr:== | ||
| - | <tt>expr</tt> solves mathematical expressions. It does not work with strings, if you want to use those, see [[{{FULLPAGENAME}}#.23ifeq:|ifeq]]. | + | <tt>expr</tt> solves mathematical expressions. It does not work with strings, if you want to use those, see [[{{FULLPAGENAME}}#.23ifeq:|ifeq]]. It also only works with numerical entries. |
{| width="100%" border="5" cellspacing="2" cellpadding="2" style="font-size:15px;text-align:center;" | {| width="100%" border="5" cellspacing="2" cellpadding="2" style="font-size:15px;text-align:center;" | ||
|- bgcolor="#FFFF00" | |- bgcolor="#FFFF00" | ||
| Line 46: | Line 46: | ||
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: | 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: | ||
<pre>{{#if: {{{parameter|}}} | Parameter is defined | Parameter is not defined }}</pre> | <pre>{{#if: {{{parameter|}}} | Parameter is defined | Parameter is not defined }}</pre> | ||
| - | If the user types <nowiki>{{templatename|parameter=true}}</nowiki> or | + | If the user types <nowiki>{{templatename|parameter=true}}</nowiki> or something similar, the result is "Parameter is defined". However, if they type <nowiki>{{templatename}}</nowiki>, the result it "Parameter is not defined". |
| - | This does not solve expressions. For example, if you type <nowiki>{{#if: 30 - 30 = 50 | 1 | 0 }}</nowiki>, the result will be 1, since 30 - 30 = 50 is not empty. | + | This does not solve expressions. For example, if you type <nowiki>{{#if: 30 - 30 = 50 | 1 | 0 }}</nowiki>, the result will be 1, since 30 - 30 = 50 is not empty. If you want to do if-then-else using expressions, see [[{{FULLPAGENAME}}#.23ifexpr:|#ifexpr]]. |
| + | ==#ifeq:== | ||
| + | |||
| + | <tt>ifeq</tt> compares two strings and then does an then-else process. To use: | ||
| + | <pre>{{#ifeq: <text 1> | <text 2> | <if equal> | <if not equal> }}</pre> | ||
| + | |||
| + | If text 1 and text 2 are equal, then it does the <nowiki><ifequal></nowiki> text. Otherwise, it does the <nowiki><ifnotequal></nowiki> text. | ||
| + | |||
| + | Some examples: | ||
| + | |||
| + | *'''<nowiki>{{#ifeq: {{NAMESPACE}} | Help | This page is in the Help Namespace | This page is not in the Help Namespace }}</nowiki>''' shows up as '''{{#ifeq: {{NAMESPACE}} | Help | This page is in the Help Namespace | This page is not in the Help Namespace }}'''. | ||
| + | *'''<nowiki>{{#ifeq: 7 | +000007 | Seven = Seven | Seven is not equal to Seven }}</nowiki>''' shows up as '''{{#ifeq: 7 | +000007 | Seven = Seven | Seven is not equal to Seven }}''' | ||
| + | |||
| + | ifeq is case-sensitive. | ||
| + | |||
| + | '''<nowiki>{{#ifeq: capital | Capital | Equal | Not Equal }}</nowiki>''' shows up as '''{{#ifeq: capital | Capital | Equal | Not Equal }}'''. | ||
| + | |||
| + | ==#ifexist:== | ||
| + | <tt>ifexist</tt> does an if-then-else process depending on if a page exists. Syntax: | ||
| + | <pre>{{#ifexist: <page name> | <if exists> | <if does not exist> }}</pre> | ||
| + | |||
| + | ifexist does not work with interwiki links. | ||
| + | |||
| + | Example: | ||
| + | |||
| + | '''<nowiki>{{#ifexist: sbemail | [[Strong Bad Email]] | [[Main Page]] }}</nowiki>''' gives '''{{#ifexist: sbemail | [[Strong Bad Email]] | [[Main Page]] }}''' because "sbemail" {{#ifexist: sbemail | exists | does not exist }}. | ||
| + | |||
| + | ==#ifexpr:== | ||
| + | |||
| + | <tt>ifexpr</tt> is a combination of if-then-else and <tt>expr</tt>. It can only be done with numbers, just like <tt>expr</tt>. Syntax: | ||
| + | <pre>{{#ifexpr: <expression> | <if true> | <if false> }}</pre> | ||
| + | |||
| + | Some examples: | ||
| + | |||
| + | *'''<nowiki>{{#ifexpr: 30 / 40 = 120 | yes | no }}</nowiki>''' shows up as '''{{#ifexpr: 30 / 40 = 120 | yes | no }}'''. | ||
| + | *'''<nowiki>{{#ifexpr: {{PAGENAME}} = ParserFunctions | This is a help page | No}}</nowiki>''' shows up as '''{{#ifexpr: {{PAGENAME}} = ParserFunctions | This is a help page | No}}''' because PAGENAME is not a number. | ||
| + | |||
| + | ==#switch:== | ||
| + | |||
| + | ==#time:== | ||
| + | |||
| + | ==#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: | ||
| + | |||
| + | <pre>{{rand: <minimum> | <maximum> }}</pre> | ||
| + | |||
| + | The minimum is the smallest number it can generate, the maximum is the largest. | ||
| + | |||
| + | Examples: | ||
| + | |||
| + | *'''<nowiki>{{#rand: 1 | 50 }}</nowiki>''' generates '''{{#rand: 1 | 50 }}'''. | ||
| + | *'''<nowiki>{{#rand: 1 | 500000 }}</nowiki>''' generates '''{{#rand: 1 | 500000 }}'''. | ||
| + | *'''<nowiki>{{#rand: .5 | 5.5 }}</nowiki>''' generates '''{{#rand: .5 | 5.5 }}'''. | ||
[[Category:Help|{{PAGENAME}}]] | [[Category:Help|{{PAGENAME}}]] | ||
Revision as of 23:33, 27 October 2007
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:
#time:
#rand:
rand 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:
{{rand: <minimum> | <maximum> }}
The minimum is the smallest number it can generate, the maximum is the largest.
Examples:
- {{#rand: 1 | 50 }} generates 10.
- {{#rand: 1 | 500000 }} generates 425441.
- {{#rand: .5 | 5.5 }} generates 4.
