How To...Create A Template: Difference between revisions
(Created page with "Welcome to this "how to create a template" guide. Disclaimer, I'm no expert myself and I'm writing this guide as much as anything to serve as a point of reference for myself when editing templates. The aim is the guide will be as foolproof as possible, for my own benefit and for anyone else who can make use of it. == The Basics == There are many uses for templates but in their simplest form is simply a page that an editor has created, that can be called upon on other pa...") |
mNo edit summary |
||
Line 7: | Line 7: | ||
* A pre-made table | * A pre-made table | ||
For example, if I created the template called "Template:Animals" and added the text "Welcome to this page, all about", I could call this template on pages names "Dog", "Cat" etc. To call the template, I would simply write the following: | For example, if I created the template called "Template:Animals" and added the text "Welcome to this page, all about", I could then call this template on pages names "Dog", "Cat" etc. To call the template, I would simply write the following: | ||
<pre>{{Animals}}</pre> | <pre>{{Animals}}</pre> | ||
I could then add the name of each animal after the template call. So on the dog page, I would write the following code: | I could then add the name of each animal after the template call. So on the dog page, I would write the following code: | ||
<pre>{{Animals}} Dogs</pre> | <pre>{{Animals}} Dogs</pre> | ||
Which then | Which would then show on the page as: | ||
<pre>Welcome to this page, all about Dogs</pre> | <pre>Welcome to this page, all about Dogs</pre> | ||
== Parameters == | |||
Parameters can be used to allow an editor to eaisly add information to a page, which will then be displayed in a pre-determined way. The name "Infobox" is commonly used to describe this and it's more easily described with examples. | |||
First of all the template needs some code so it knows how to display the information an editor will provide. I will use a simple table in my examples. On the left is my table code and on the right is the simple table it produces. | |||
<div class="flex-container"> | |||
<div class="flex-container-item-2"> | |||
<pre>{| width="50% border="1px #aaa solid"; | |||
! style="border:1px #aaa solid" colspan="2"| Animals | |||
|- | |||
! style="border:1px #aaa solid" width="50%" | Type | |||
| style="border:1px #aaa solid" width="50%" | | |||
|}</pre></div> | |||
<div class="flex-container-item-2"> | |||
{| width="100% border="1px #aaa solid"; | |||
! style="border:1px #aaa solid" colspan="2"| Animals | |||
|- | |||
! style="border:1px #aaa solid" width="50%" | Type | |||
| style="border:1px #aaa solid" width="50%" | | |||
|}</div></div> | |||
Now that I have my table, it's time to add a parameter. Looking at the table, we need to add the "type" parameter, which will fill the empty table cell, adjacent to type. To create a parameter, we simply surround text with '''3 curly brackets''', like so: | |||
<pre>{{{type}}}</pre> | |||
Whatever text we surround is the '''parameter name'''. We need to add this parameter to our table. | |||
<pre>|- | |||
! style="border:1px #aaa solid" width="50%" | Type | |||
| style="border:1px #aaa solid" width="50%" | {{{type}}}</pre> | |||
We can now use the template and the newly created parameter. On the left in the next example is how to use the template and it's parameter and on the right is the output. | |||
<div class="flex-container"> | |||
<div class="flex-container-item-2"> | |||
<pre>{{Animals | |||
| type = Rabbit | |||
}}</pre></div> | |||
<div class="flex-container-item-2"> | |||
{| width="100% border="1px #aaa solid"; | |||
! style="border:1px #aaa solid" colspan="2"| Animals | |||
|- | |||
! style="border:1px #aaa solid" width="50%" | Type | |||
| style="border:1px #aaa solid" width="50%" | Rabbit | |||
|}</div></div> |
Revision as of 23:15, 22 January 2024
Welcome to this "how to create a template" guide. Disclaimer, I'm no expert myself and I'm writing this guide as much as anything to serve as a point of reference for myself when editing templates. The aim is the guide will be as foolproof as possible, for my own benefit and for anyone else who can make use of it.
The Basics
There are many uses for templates but in their simplest form is simply a page that an editor has created, that can be called upon on other pages. You could create a template to call upon:
- An image
- Text
- A pre-made table
For example, if I created the template called "Template:Animals" and added the text "Welcome to this page, all about", I could then call this template on pages names "Dog", "Cat" etc. To call the template, I would simply write the following:
{{Animals}}
I could then add the name of each animal after the template call. So on the dog page, I would write the following code:
{{Animals}} Dogs
Which would then show on the page as:
Welcome to this page, all about Dogs
Parameters
Parameters can be used to allow an editor to eaisly add information to a page, which will then be displayed in a pre-determined way. The name "Infobox" is commonly used to describe this and it's more easily described with examples.
First of all the template needs some code so it knows how to display the information an editor will provide. I will use a simple table in my examples. On the left is my table code and on the right is the simple table it produces.
{| width="50% border="1px #aaa solid"; ! style="border:1px #aaa solid" colspan="2"| Animals |- ! style="border:1px #aaa solid" width="50%" | Type | style="border:1px #aaa solid" width="50%" | |}
Animals | |
---|---|
Type |
Now that I have my table, it's time to add a parameter. Looking at the table, we need to add the "type" parameter, which will fill the empty table cell, adjacent to type. To create a parameter, we simply surround text with 3 curly brackets, like so:
{{{type}}}
Whatever text we surround is the parameter name. We need to add this parameter to our table.
|- ! style="border:1px #aaa solid" width="50%" | Type | style="border:1px #aaa solid" width="50%" | {{{type}}}
We can now use the template and the newly created parameter. On the left in the next example is how to use the template and it's parameter and on the right is the output.
{{Animals | type = Rabbit }}
Animals | |
---|---|
Type | Rabbit |