Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
{{Header Nav|game=StrategyWiki:Guide}} | {{Header Nav|game=StrategyWiki:Guide}} | ||
:''Template redirects here, for a list of templates see [[:Category:Templates]]'' | |||
:''Template redirects here | |||
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). | 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). | ||
Line 11: | Line 10: | ||
Every template must be placed within a category, either [[:Category:Templates]] or [[:Category:Guide-specific templates]]. | Every template must be placed within a category, either [[:Category:Templates]] or [[:Category:Guide-specific templates]]. | ||
If you want to modify a template it's usually good to discuss it within the talk page if it's a major change. | If you want to modify a template it's usually good to discuss it within the talk page if it's a major change. Locked templates such as [[Template:Infobox]] require a sysop/admin to make the change so discussion is of course critical. | ||
Categorization, careful naming, and maintaining a hierarchy is key in ensuring that our templates don't get cluttered. Templates are critical for reducing redundancy, but they are powerful tools that must be given respect and much thought so that they don't in themselves become redundant. | Categorization, careful naming, and maintaining a hierarchy is key in ensuring that our templates don't get cluttered. Templates are critical for reducing redundancy, but they are powerful tools that must be given respect and much thought so that they don't in themselves become redundant. | ||
==Using a template== | ==Using a template== | ||
Line 30: | Line 21: | ||
==Using parameters in templates== | ==Using parameters in templates== | ||
{|{{ | <div style="float:right"> | ||
{| {{Prettytable}} | |||
|- | |||
|bgcolor="#A7C1F2" colspan="2" align="center" |'''Template with numbered parameters''' | |||
|- | |- | ||
| | | 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''' | ||
|<pre><nowiki> | |bgcolor="#A7C1F2"|'''You get''' | ||
|- | |||
|<code><nowiki>{{Thankyou|all|~~~}}</nowiki></code> | |||
| | |||
{{Thankyou|all|[[User:Someuser|Someuser]]}} | |||
|- | |||
|bgcolor="#A7C1F2" colspan="2" align="center" |'''with named parameters''' | |||
|- | |||
| 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> | ||
|<pre><nowiki>{{ | |- | ||
|bgcolor="#A7C1F2"|'''You type''' | |||
|bgcolor="#A7C1F2"|'''You get''' | |||
|- | |||
|<pre><nowiki>{{Thankyou | |||
|reason=all | |reason=all | ||
|signature=~~~ | |signature=~~~}}</nowiki></pre> | ||
}}</nowiki></pre> | | | ||
|{{ | {{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>. | ||
'''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: | '''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 (|): <code><nowiki>{{ | When using the template on a page, you fill in the parameter values, separated by a pipe char (|): <code><nowiki>{{Thankyou|all|~~~}}</nowiki></code> or - if you have used named parameters <code><nowiki>{{Thankyou|reason=all|signature=~~~}}</nowiki></code>. 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: <code><nowiki>{{Thankyou|2=~~~|1=all}}</nowiki></code>. | ||
==Control template inclusion== | ==Control template inclusion== | ||
You can control template inclusion by the use of <code> | You can control template inclusion by the use of <code><nowiki><noinclude></nowiki></code> and | ||
<code><nowiki><includeonly></nowiki></code> tags. | |||
Anything between <code> | Anything between <code><nowiki><noinclude></nowiki></code> and <code><nowiki></noinclude></nowiki></code> will be processed and | ||
displayed only when the page is being viewed directly, not included. | |||
Possible applications are: | Possible applications are: | ||
Line 74: | Line 77: | ||
* Explanatory text about how to use the template | * Explanatory text about how to use the template | ||
The converse is <code> | The converse is <code><nowiki><includeonly></nowiki></code>. Text between <code><nowiki><includeonly></nowiki></code> and | ||
<code><nowiki></includeonly></nowiki></code> 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 | Note that the usual update problems apply -- if you change the | ||
Line 85: | Line 85: | ||
won't be updated until those pages are edited. | won't be updated until those pages are edited. | ||
==Making templates useful== | ==Making templates useful== | ||
For templates to be effective | 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 | |||
<div style=" | <div style="display:table; width:auto;"> | ||
==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]]. | |||
== Advanced | |||
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 | |||
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 <nowiki>{{#if:}}</nowiki> exist and are used for different purposes. Usage of these functions is outlined below. | 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 <nowiki>{{#if:}}</nowiki> exist and are used for different purposes. Usage of these functions is outlined below. | ||
===<nowiki>{{#if:}}</nowiki>=== | |||
=== <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: | 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}} | {| {{prettytable|notwide=1}} | ||
| | |bgcolor="#A7C1F2" colspan="3" align="center"|'''Usage of <nowiki>{{#if:}}</nowiki>''' | ||
|- | |- | ||
! | !What you type | ||
! | !What you see | ||
!Why | !Why you see it | ||
|- | |- | ||
|<pre>{{#if:{{{1|}}}|not empty|empty}}</pre> | |<pre>{{#if:{{{1|}}}|not empty|empty}}</pre> | ||
Line 159: | Line 128: | ||
|} | |} | ||
=== <nowiki>{{#expr:}}</nowiki> === | |||
===<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> | <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> | {{#expr:<expression to be evaluated>}}</pre> | ||
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>''' | ||
|- | |- | ||
! Operator | ! ''Operator'' | ||
! Operation | ! ''Operation'' | ||
! Example | ! ''Example'' | ||
|- | |- | ||
|rowspan="2" colspan="2" align="center"| | |rowspan="2" colspan="2" align="center"| none | ||
| | | | ||
<nowiki>{{#expr: 123456789012345}}</nowiki> = {{#expr: 123456789012345}} | <nowiki>{{#expr: 123456789012345}}</nowiki> = {{#expr: 123456789012345}} | ||
Line 288: | Line 258: | ||
|} | |} | ||
=== <nowiki>{{#ifeq:}}</nowiki> === | ===<nowiki>{{#ifeq:}}</nowiki>=== | ||
This function compares a string or numerical value in <parameter to test> to the string or numerical value in <parameter to compare test to>. If you wish to compare strings represented by numbers and numeral operators, enclose the string within "" to force a string comparison. <What to display if test is true> and <what to display if test is false> are optional, but one must be used unless you wish to return absolutely nothing. Also, when testing operations, use <nowiki>{{#expr:}}</nowiki>. The usage for <nowiki>{{#ifeq:}}</nowiki> is as follows: | This function compares a string or numerical value in <parameter to test> to the string or numerical value in <parameter to compare test to>. If you wish to compare strings represented by numbers and numeral operators, enclose the string within "" to force a string comparison. <What to display if test is true> and <what to display if test is false> are optional, but one must be used unless you wish to return absolutely nothing. Also, when testing operations, use <nowiki>{{#expr:}}</nowiki>. The usage for <nowiki>{{#ifeq:}}</nowiki> is as follows: | ||
<pre>{{#ifeq:<parameter to test> | <pre>{{#ifeq:<parameter to test> | ||
|<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> | |<what to display if test is false>}}</pre> | ||
}}</pre> | |||
{|{{prettytable}} | {| {{prettytable}} | ||
| | |bgcolor="#A7C1F2" colspan="2" align="center"|'''Usage of <nowiki>{{#ifeq:}}</nowiki>''' | ||
|- | |- | ||
! | !What you type | ||
! | !What is displayed | ||
|- | |- | ||
|<pre>{{#ifeq:+07|007|yes|no}}</pre> | |<pre>{{#ifeq:+07|007|yes|no}}</pre> | ||
Line 315: | Line 284: | ||
|} | |} | ||
== | ==Usage== | ||
Allows to establish a link to a subject: | |||
<pre>{{ | <div><pre> | ||
| | {{NameOfTemplate|Term1+Term2+Term3}} | ||
</pre></div> | |||
}}</pre | |||
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= | {{Footer Nav|game=StrategyWiki:Guide|prevpage=Tables|nextpage=Preview and save}} | ||
</div> |