From StrategyWiki, the video game walkthrough and strategy guide wiki
Jump to navigation Jump to search
m (removed redundancy)
(#expr documentation (from soon-to-be-deleted template:expr))
Line 118: Line 118:
|The test parameter was empty, so that was the result. When skipping sections in the middle of the #if construct, you still need the pipes to go to later sections.
|The test parameter was empty, so that was the result. When skipping sections in the middle of the #if construct, you still need the pipes to go to later sections.
|}
|}
</div>
 
 
===<nowiki>{{#expr:}}</nowiki>===
<nowiki>{{#expr:}}</nowiki> evaluates a mathematical expression or boolean comparison (where the results are only 1 or 0, for true and false respectively). It is used with the syntax:<pre>
{{#expr:<expression to be evaluated>}}</pre>
The operands that can be used in <nowiki>{{#expr:}}</nowiki> are listed below.
 
{| {{prettytable}}
|bgcolor="#A7C1F2" colspan="3" align="center"|'''Usage of <nowiki>{{#expr:}}</nowiki>'''
|-
! ''Operator''
! ''Operation''
! ''Example''
|-
|rowspan="2" colspan="2" align="center"| none
|
<nowiki>{{expr|123456789012345}}</nowiki> = {{#expr: 123456789012345}}
|-
|
<nowiki>{{expr|0.000001}}</nowiki> = {{#expr: 0.000001}}
|-
! ( )
| Grouping operators
|
<nowiki>{{expr|(30 + 7) * 7 }}</nowiki> = {{#expr: (30 + 7) * 7 }}
|-
! +
| Unary '''<tt>+</tt>''' sign
|
<nowiki>{{expr|+30 * +7}}</nowiki> = {{#expr: +30 * +7}}
|-
! -
| Unary '''<tt>-</tt>''' sign (negation)
|
<nowiki>{{expr|-30 * -7}}</nowiki> = {{#expr: -30 * -7}}
|-
! not
|  Unary NOT, logical NOT
|
<nowiki>{{expr|not 0 * 7}}</nowiki> = {{#expr: not 0 * 7}}<br />
<nowiki>{{expr|not 30 + 7}}</nowiki> = {{#expr: not 30+7}}
|-
! *
| Multiplication
|
<nowiki>{{expr|30 * 7}}</nowiki> = {{#expr: 30 * 7}}
|-
! /
| Division, same as '''div'''
|
<nowiki>{{expr|30 / 7}}</nowiki> = {{#expr: 30 / 7}}
|-
! div
| Division, same as '''/''',<br />no integer division
|
<nowiki>{{expr|30 div 7}}</nowiki> = {{#expr: 30 div 7}}<br />
<nowiki>{{expr|5 div 2 * 2 + 5 mod 2}}</nowiki> = {{#expr: 5 div 2 * 2 + 5 mod 2}}
|-
! mod
| "Modulo", remainder of division after truncating both operands to an integer.<br />Caveat, '''div''' and '''mod''' are different from all programming languages.
|
<nowiki>{{expr|30 mod 7}}</nowiki> = {{#expr: 30 mod 7}}<br />
<nowiki>{{expr|-8 mod -3}}</nowiki> = {{#expr: -8 mod -3}}<br />
<nowiki>{{expr|-8 mod +3}}</nowiki> = {{#expr: -8 mod +3}}<br />
<nowiki>{{expr|8 mod 2.7}}</nowiki> = {{#expr: 8 mod 2.7}}<br />
<nowiki>{{expr|8 mod 3.2}}</nowiki> = {{#expr: 8 mod 3.2}}<br />
<nowiki>{{expr|8.9 mod 3}}</nowiki> = {{#expr: 8.9 mod 3}}
|-
! <tt>+</tt>
| Addition
|
<nowiki>{{expr|30 + 7}}</nowiki> = {{#expr: 30 + 7}}
|-
! <tt>-</tt>
| Subtraction
|
<nowiki>{{expr|30 - 7}}</nowiki> = {{#expr: 30 - 7}}
|-
! round
| Rounds off the number on the left to the power of 1/10 given on the right
|
<nowiki>{{expr|30 / 7 round 3}}</nowiki> = {{#expr: 30 / 7 round 3}}<br />
<nowiki>{{expr|30 / 7 round 0}}</nowiki> = {{#expr: 30 / 7 round 0}}<br />
<nowiki>{{expr|3456 round -2}}</nowiki> = {{#expr: 3456 round -2}}
|-
! =
| Equality (numerical incl. logical)
|
<nowiki>{{expr|30 = 7}}</nowiki> = {{#expr: 30 = 7}}
|-
! &lt;&gt;
| Inequality, same as '''!='''
|
<nowiki>{{expr|30 &lt;&gt; 7}}</nowiki> = {{#expr: 30 <> 7}}
|-
! !=
| Inequality, same as '''&lt;&gt;''', logical ''xor''
|
<nowiki>{{expr|1 != 0}}</nowiki> = {{#expr: 1 != 0}}
|-
! &lt;
| Less than
|
<nowiki>{{expr|30 &lt; 7}}</nowiki> = {{#expr: 30 < 7}}
|-
! &gt;
| Greater than
|
<nowiki>{{expr|30 &gt; 7}}</nowiki> = {{#expr: 30 > 7}}
|-
! &lt;=
| Less than or equal to
|
<nowiki>{{expr|30 &lt;= 7}}</nowiki> = {{#expr: 30 <= 7}}
|-
! &gt;=
| Greater than or equal to
|
<nowiki>{{expr|30 &gt;= 7}}</nowiki> = {{#expr: 30 >= 7}}
|-
! and
| Logical AND
|
<nowiki>{{expr|4 &lt; 5 and 4 mod 2}}</nowiki> = {{#expr: 4<5 and 4 mod 2}}
|-
! or
| Logical OR
|
<nowiki>{{expr|4 &lt; 5 or 4 mod 2}}</nowiki> = {{#expr: 4<5 or 4 mod 2}}
|}


==Usage==
==Usage==

Revision as of 15:39, 11 March 2007

Template:All Game Nav If you have standard texts you want to include on several pages, the MediaWiki template feature comes into play (like the tag above which is included in the pages of the Help namespace).

Creating a template

Template names are prefixed with Template:, you create them like any other wiki page.

Using a template

Templates are wiki pages which can be used in other pages in three ways:

{{Name}} includes the current content of the page "[[Template:Name]]".
{{subst:Name}} inserts the content of the page "[[Template:Name]]" when you save your text. Subst will use the template one time for the creation of the page; afterwards if the template is updated, the page that subst:template was used on will not have those changes made to them.
{{msgnw:Name}} includes the template in raw wiki syntax, like <nowiki> does

Using parameters in templates

Template with numbered parameters
 
'''A little thank you...'''<br>
<small>for {{{1}}}.<br>
hugs, {{{2}}}</small>
You type You get
{{Thankyou|all|~~~}}

Template:Thankyou

with named parameters
 
'''A little thank you...'''<br>
<small>for {{{reason}}}.<br>
hugs, {{{signature}}}</small>
You type You get
{{Thankyou
|reason=all
|signature=~~~}}

Template:Thankyou

You can define parameters in templates either numbered as {{{1}}} or named {{{param}}}.

Example: you want a little thank you note you can put other users on their talk page with a reason and your signature. In the Template:Thankyou you enter your text.

When using the template on a page, you fill in the parameter values, separated by a pipe char (|): {{Thankyou|all|~~~}} or - if you have used named parameters {{Thankyou|reason=all|signature=~~~}}. The advantage of using named parameters in your template is that they are flexible in order. It also makes the template easier to understand if you have many parameters. If you want to change the order of numbered parameters, you have to mention them explicitly: {{Thankyou|2=~~~|1=all}}.

Control template inclusion

You can control template inclusion by the use of <noinclude> and <includeonly> tags.

Anything between <noinclude> and </noinclude> will be processed and displayed only when the page is being viewed directly, not included.

Possible applications are:

  • Categorising templates
  • Interlanguage links to similar templates in other languages
  • Explanatory text about how to use the template

The converse is <includeonly>. Text between <includeonly> and </includeonly> will be processed and displayed only when the page is being included. The obvious application is to add all pages containing a given template to a category.

Note that the usual update problems apply -- if you change the categories inside a template, the categories of the referring pages won't be updated until those pages are edited.

Making templates useful

For templates to be effective users need to find them and be able to use them. Wikis are not user friendly when it comes to finding, using, and working with templates. A simple technique is to have a usage on the template page. For example

Advanced Template Usage

We already covered parameters, think of them as variables (temporarily stored data). MediaWiki allows us to look at those variables and check if they even contain anything. What this lets us do is create templates in which only certain parts appear if the data exists within them, for instance in Template:Infobox and Template:Final Fantasy VII/Boss.

The {{#if:}} function is what lets us manipulate wiki code in this way. We can test for existence within a parameter, then display a certain text if it exists, and a certain text if it doesn't. This way we can display and hide text when empty spaces would normally exist. Other parser functions like exist and are used for different purposes. Usage of these functions is outlined below.

{{#if:}}

The function allows us to test a variable to see if it is empty or not. It returns the first value (value after the first pipe) if it is not empty and the second value (value after the second pipe) if it is. It is used with the syntax:

{{#if:<variable to test>|<what to display if test is not empty>|<what to display if test is empty>}}
Usage of {{#if:}}
What you type What you see Why you see it
{{#if:{{{1|}}}|not empty|empty}}
empty There is no defined value for the variable {{{1}}}, so it jumps to the default value after the pipe character (which is nothing in this case). This default value of nothing returns the empty value.
{{#if:{{{1|a}}}|not empty|empty}}
not empty Because {{{1}}} is again not defined, so it jumps to the default value of "a". Because "a" is a non-empty string, {{#if:}} returns the not empty value.
{{#if:|not empty|empty}}
empty The parameter being tested is empty, so it returns that value.
{{#if:hello|not empty|empty}}
not empty The string "hello" is not an empty string, so it returns the not empty value.
{{#if:hello|not empty}}
not empty It is possible to skip unneeded parts of the #if construct, in this case, the <what to display if test is empty> part.
{{#if:||empty}}
empty The test parameter was empty, so that was the result. When skipping sections in the middle of the #if construct, you still need the pipes to go to later sections.


{{#expr:}}

{{#expr:}} evaluates a mathematical expression or boolean comparison (where the results are only 1 or 0, for true and false respectively). It is used with the syntax:
{{#expr:<expression to be evaluated>}}

The operands that can be used in {{#expr:}} are listed below.

Usage of {{#expr:}}
Operator Operation Example
none

{{expr|123456789012345}} = 1.2345678901234E+14

{{expr|0.000001}} = 1.0E-6

( ) Grouping operators

{{expr|(30 + 7) * 7 }} = 259

+ Unary + sign

{{expr|+30 * +7}} = 210

- Unary - sign (negation)

{{expr|-30 * -7}} = 210

not Unary NOT, logical NOT

{{expr|not 0 * 7}} = 7
{{expr|not 30 + 7}} = 7

* Multiplication

{{expr|30 * 7}} = 210

/ Division, same as div

{{expr|30 / 7}} = 4.2857142857143

div Division, same as /,
no integer division

{{expr|30 div 7}} = 4.2857142857143
{{expr|5 div 2 * 2 + 5 mod 2}} = 6

mod "Modulo", remainder of division after truncating both operands to an integer.
Caveat, div and mod are different from all programming languages.

{{expr|30 mod 7}} = 2
{{expr|-8 mod -3}} = -2
{{expr|-8 mod +3}} = -2
{{expr|8 mod 2.7}} = 0
{{expr|8 mod 3.2}} = 2
{{expr|8.9 mod 3}} = 2

+ Addition

{{expr|30 + 7}} = 37

- Subtraction

{{expr|30 - 7}} = 23

round Rounds off the number on the left to the power of 1/10 given on the right

{{expr|30 / 7 round 3}} = 4.286
{{expr|30 / 7 round 0}} = 4
{{expr|3456 round -2}} = 3500

= Equality (numerical incl. logical)

{{expr|30 = 7}} = 0

<> Inequality, same as !=

{{expr|30 <> 7}} = 1

!= Inequality, same as <>, logical xor

{{expr|1 != 0}} = 1

< Less than

{{expr|30 < 7}} = 0

> Greater than

{{expr|30 > 7}} = 1

<= Less than or equal to

{{expr|30 <= 7}} = 0

>= Greater than or equal to

{{expr|30 >= 7}} = 1

and Logical AND

{{expr|4 < 5 and 4 mod 2}} = 0

or Logical OR

{{expr|4 < 5 or 4 mod 2}} = 1

Usage

Allows to establish a link to a subject:

{{NameOfTemplate|Term1+Term2+Term3}}

The user can simply copy and paste the template to establish a new page that is similar to other pages. The example demonstrated is trival true, however a working example that demonstrates how templates can be used in complex situations to save time, accuracy and help categories pages on specialty topics more easily. see working example here.

See also