Help:Templates: Difference between revisions

Jump to navigation Jump to search
934 bytes removed ,  12 July 2007
m
Cleanup
(→‎See also: rm section because it's at the top, feel free to revert me)
m (Cleanup)
Line 21: Line 21:


==Using parameters in templates==
==Using parameters in templates==
<div style="float:right">
{|{{prettytable}}
{| {{Prettytable}}
! Description
! Template text
! You type…
! You get…
|-
|-
|bgcolor="#A7C1F2" colspan="2" align="center" |'''Template with numbered parameters'''
| Template with numbered parameters
|-
|<pre><nowiki>  
| colspan="2" |
<pre><nowiki>  
'''A little thank you...'''<br>
'''A little thank you...'''<br>
<small>for {{{1}}}.<br>
<small>for {{{1}}}.<br>
hugs, {{{2}}}</small>
hugs, {{{2}}}</small>
</nowiki></pre>  
</nowiki></pre>  
|-
|bgcolor="#A7C1F2"|'''You type'''
|bgcolor="#A7C1F2"|'''You get'''
|-
|<code><nowiki>{{Thankyou|all|~~~}}</nowiki></code>
|<code><nowiki>{{Thankyou|all|~~~}}</nowiki></code>
|
|{{Thankyou|all|[[User:Someuser|Someuser]]}}
{{Thankyou|all|[[User:Someuser|Someuser]]}}
|-
|-
|bgcolor="#A7C1F2" colspan="2" align="center" |'''with named parameters'''
| Template with named parameters
|-
|<pre><nowiki>  
| colspan="2" |
<pre><nowiki>  
'''A little thank you...'''<br>
'''A little thank you...'''<br>
<small>for {{{reason}}}.<br>
<small>for {{{reason}}}.<br>
hugs, {{{signature}}}</small>
hugs, {{{signature}}}</small>
</nowiki></pre>  
</nowiki></pre>  
|-
|bgcolor="#A7C1F2"|'''You type'''
|bgcolor="#A7C1F2"|'''You get'''
|-
|<pre><nowiki>{{Thankyou
|<pre><nowiki>{{Thankyou
|reason=all
|reason=all
|signature=~~~}}</nowiki></pre>
|signature=~~~
|
}}</nowiki></pre>
{{Thankyou|all|[[User:Someuser|Someuser]]}}
|{{Thankyou|all|[[User:Someuser|Someuser]]}}
|}
|}
</div>
 
You can define parameters in templates either numbered as <code><nowiki>{{{1}}}</nowiki></code> or named <code><nowiki>{{{param}}}</nowiki></code>.   
You can define parameters in templates either numbered as <code><nowiki>{{{1}}}</nowiki></code> or named <code><nowiki>{{{param}}}</nowiki></code>.   


Line 88: Line 78:
For example
For example
<div style="display:table; width:auto;">
<div style="display:table; width:auto;">
==Advanced Template Usage==
==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]].
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]].


Line 96: Line 86:
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:
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>
<pre>{{#if:<variable to test>|<what to display if test is not empty>|<what to display if test is empty>}}</pre>
{| {{prettytable|notwide=1}}
{|{{prettytable}}
|bgcolor="#A7C1F2" colspan="3" align="center"|'''Usage of <nowiki>{{#if:}}</nowiki>'''
|+ Usage of <nowiki>{{#if:}}</nowiki>
|-
|-
!What you type
!You type…
!What you see
!You see…
!Why you see it
!Why?
|-
|-
|<pre>{{#if:{{{1|}}}|not empty|empty}}</pre>
|<pre>{{#if:{{{1|}}}|not empty|empty}}</pre>
Line 127: Line 117:
|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.
|}
|}


===<nowiki>{{#expr:}}</nowiki>===
===<nowiki>{{#expr:}}</nowiki>===
Line 134: Line 123:
The operands that can be used in <nowiki>{{#expr:}}</nowiki> are listed below.
The operands that can be used in <nowiki>{{#expr:}}</nowiki> are listed below.


{| {{prettytable}}
{|{{prettytable}}
|bgcolor="#A7C1F2" colspan="3" align="center"|'''Usage of <nowiki>{{#expr:}}</nowiki>'''
|+ Usage of <nowiki>{{#expr:}}</nowiki>
|-
|-
! ''Operator''
! Operator
! ''Operation''
! Operation
! ''Example''
! Example
|-
|-
|rowspan="2" colspan="2" align="center"| none
|rowspan="2" colspan="2" align="center"| None
|
|
<nowiki>{{#expr: 123456789012345}}</nowiki> = {{#expr: 123456789012345}}
<nowiki>{{#expr: 123456789012345}}</nowiki> = {{#expr: 123456789012345}}
Line 263: Line 252:
|<parameter to compare test to>
|<parameter to compare test to>
|<what to display if test is true>
|<what to display if test is true>
|<what to display if test is false>}}</pre>
|<what to display if test is false>
}}</pre>


{| {{prettytable}}
{|{{prettytable}}
|bgcolor="#A7C1F2" colspan="2" align="center"|'''Usage of <nowiki>{{#ifeq:}}</nowiki>'''
|+ Usage of <nowiki>{{#ifeq:}}</nowiki>
|-
|-
!What you type
!You type…
!What is displayed
!You see…
|-
|-
|<pre>{{#ifeq:+07|007|yes|no}}</pre>
|<pre>{{#ifeq:+07|007|yes|no}}</pre>
Line 283: Line 273:
|{{#ifeq:{{#expr:7*5+5}}|40|yes|no}}
|{{#ifeq:{{#expr:7*5+5}}|40|yes|no}}
|}
|}
==Usage==
Allows to establish a link to a subject:
<div><pre>
{{NameOfTemplate|Term1+Term2+Term3}}
</pre></div>
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 [[Template:Header Nav|here]].


{{Footer Nav|game=StrategyWiki:Guide|prevpage=Tables|nextpage=Preview and save}}
{{Footer Nav|game=StrategyWiki:Guide|prevpage=Tables|nextpage=Preview and save}}
</div>
</div>

Navigation menu