Help:Templates: Difference between revisions

From StrategyWiki, the video game walkthrough and strategy guide wiki
3,214 bytes removed ,  11 March 2007
m
removed redundancy
m (removed redundancy)
Line 119: Line 119:
|}
|}
</div>
</div>
==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 <nowiki>{{#if:}}</nowiki> 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 {{#if:}} exist and are used for different purposes. Usage of these functions is outlined below.
===<nowiki>{{#if:}}</nowiki>===
The {{#if:}} 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:
<pre>{{#if:<variable to test>|<what to display if test is not empty>|<what to display if test is empty>}}</pre>
{| {{prettytable}}
|bgcolor="#A7C1F2" colspan="3" align="center"|'''Usage of <nowiki>{{#if:}}</nowiki>'''
|-
!span="25%"|What you type
!span="25%"|What you see
!span="50%"|Why you see it
|-
|<pre>{{#if:{{{1|}}}|not empty|empty}}</pre>
|empty
|There is no defined value for the variable <nowiki>{{{1}}}</nowiki>, 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.
|-
|<pre>{{#if:{{{1|a}}}|not empty|empty}}</pre>
|not empty
|Because <nowiki>{{{1}}}</nowiki> is again not defined, so it jumps to the default value of "a". Because "a" is a non-empty string, <nowiki>{{#if:}}</nowiki> returns the not empty value.
|-
|<pre>{{#if:|not empty|empty}}</pre>
|empty
|The parameter being tested is empty, so it returns that value.
|-
|<pre>{{#if:hello|not empty|empty}}</pre>
|not empty
|The string "hello" is not an empty string, so it returns the not empty value.
|-
|<pre>{{#if:hello|not empty}}</pre>
|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.
|-
|<pre>{{#if:||empty}}</pre>
|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.
|}
==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 <nowiki>{{qif}}</nowiki> template 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.


==Usage==
==Usage==
Line 176: Line 131:
*[[:Category:Templates]]
*[[:Category:Templates]]
{{Footer Nav|game=StrategyWiki:Guide|backpage=Tables|nextpage=Preview and save}}
{{Footer Nav|game=StrategyWiki:Guide|backpage=Tables|nextpage=Preview and save}}
</div>