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: | ||
{{ | {{All Game Nav|game=StrategyWiki:Guide}} | ||
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). | ||
==Creating a template== | ==Creating a template== | ||
Template names are prefixed with <code>Template:</code>, you create them like any other wiki page. | Template names are prefixed with <code>Template:</code>, you create them like any other wiki page. | ||
==Using a template== | ==Using a template== | ||
Line 30: | Line 12: | ||
==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 68: | ||
* 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 76: | ||
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 | 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>=== | |||
=== <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 119: | ||
|} | |} | ||
=== <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 249: | ||
|} | |} | ||
== | ==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:All Game Nav|here]]. | |||
| | |||
{{Footer Nav|game=StrategyWiki:Guide| | == See also == | ||
*[[:Category:Templates]] | |||
{{Footer Nav|game=StrategyWiki:Guide|backpage=Tables|nextpage=Preview and save}} | |||
</div> |