Help:Templates: Difference between revisions

From 118Wiki
Jump to navigation Jump to search
(Link to Mediawiki: Help:Templates)
(rewrite, wip)
Line 1: Line 1:
Templates are a way to include commonly reused segments of text or code. They also make pages sources easier to read by removing complicated elements.
{{118Wikiheader}}
{{Help page}}


==Example==
This is an '''introduction to templates''' in 118Wiki.


For instance adding <nowiki>{{Template:NPC ship}}</nowiki> to a page makes it add this:
{{LCARS-bar-heading|What is a template?|COLOR={{Color|red}}}}
{{Template:NPC ship}}
A template is a piece of code that can be used on multiple pages. A very simple template could be just a string of text, but most of them contain an amount of coding and programming using HTML, CSS, magic words, parser functions and other methods.


This is a reasonably large segment of code, that would be inconvenient to add to many pages that require it, so it as added as a template in order to make it easier.
Using a template has several advantages, as it cuts down the required effort of having to write or copy the code to each page individually. This is especially important when the code is complicated. If the code needs to be modified, the changes can be done to the template instead of having to look up each page that uses similar code. Additionally, templates help to achieve similar visuals for each page.


==Guidelines==
{{LCARS-bar-heading|Using templates|COLOR={{Color|gold}}}}


Before we talk about how to make Templates, it is a good idea to consider '''when''' we should use templates.
=== Template call ===
The contents of a template can be added (or ''transcluded'') to a page using a ''template call''. A template call is an instruction for the system to search for that template and show its content on the ''target page'' when someone is reading it. As such, the template calls are similar to function calls in most programming languages.


# Templates should only be used for code which is likely to be re-used on a number of pages.
In source editing, a template can be called using two curly brackets around the name of the template without the “Template:” prefix. For example, <code><nowiki>{{Mirror universe}}</nowiki></code> calls the [[Template:Mirror universe]]. It is a template used to inform the readers that the page covers a [[Mirror universe]] topic. Below is what it would look like:
# Templates are unnecessary for short segments.


For instance using a template to include a universal navigation for a set of pages in a series is a good use, while creating a template for the "Stats" segment on your characters page is unnecessary.
{{Mirror universe}}


==How to create a template==
In the Visual Editor, you can add a template call to a page by opening the “Insert” menu from the toolbar and clicking “Template”. This will open a dialog box (popup) with a search bar for finding the template. After selecting a template, you may add the template to the page by clicking “Insert” in the top right corner of the dialog box.


A template can be created in the same way as a ordinary page, just instead of just typing the pages name you type Template: before it to mark it as a template.
=== Parameters ===


==More help on templates==
Templates can also take information the user gives them and change its appearance or functionality depending on the user’s input. For this purpose, the user would use ''parameters''. When calling a template, the user has an option to give a value to a parameter. The value given for a parameter can be text, files, code or even other templates.
* [http://www.mediawiki.org/wiki/Help:Templates Mediawiki: Help:Templates]
 
In Visual Editor, the dialogue will ask values to each parameter separately. You can choose which parameters you want to use.
 
In source editing, parameters are separated in the template call by | symbol (vertical bar). Parameters and what they do can typically be found on the template documentation page. There are two types of parameters, named and unnamed.
 
If the parameter is unnamed, the value given to it is separated from the templates name and other parameters by a vertical bar.
 
For example, [[Template:Crewnav]] can be used on a character page to show the officers who serve on the same ship as that character. Since Template:Crewnav uses a single unnamed parameter, you would give the value with a vertical bar separating it from the template name: <code><nowiki>{{Crewnav|USS Artemis-A}}</nowiki></code>. The result is below:
{{Crewnav|USS Artemis-A}}
 
A template may sometimes have multiple unnamed parameters. They are separated from each other using the vertical bar. In that case, the parameters always have to be in the same order!
 
For example, if you want to show one of the [[ribbons]] your character has earned, you can use [[Template:Ribbons]]. The template requires that you give the name of the ribbon, how large you want the ribbon to be in pixels and how many times the character has earned the ribbon, in this order. So, you could have a template call like <code><nowiki>{{Ribbons|Innovation Ribbon|120|2}}</nowiki></code>, with the result:
{{Ribbons|Innovation Ribbon|120|2}}
 
{{Quote box | quote = Tea, Earl Grey, hot | source = —Jean-Luc Picard | title = Example }}
Instead of unnamed parameters, many templates have named parameters. They are also separated from the template name and each other with vertical bars. The parameter’s name is given, after which comes the equality sign =, and lastly the value given to the parameter.
For example, if you would want to show a quote someone said, you may use a [[Template:Quote box]] with a template call like <code><nowiki>{{Quote box | quote = Tea, Earl Grey, hot | source = —Jean-Luc Picard | title = Example }}</nowiki></code>, with the result on the right.
 
Sometimes you might want to use unnamed parameters out of order. In that case, the ordinal of the unnamed parameter can be used as the parameter name, i.e. the first parameter has the name “1”. As such, the example with the ribbons also works with the code <code><nowiki>{{Ribbons|2=120|1=Innovation Ribbon|3=2}}</nowiki></code>.
 
{{LCARS-bar-heading|Learn more|COLOR={{Color|blue}}}}
{{UC|section=yes}}
 
=== More on the topic ===
{{Start Columns}}
* [[:Category:Templates]], category that contains most templates in 118Wiki
* [[Special:MostTranscludedPages]], an automatically updated page listing the most commonly used templates (and some other pages)
{{Column|50%}}
* [https://www.mediawiki.org/wiki/Help:Templates Templates], MediaWiki help page about templates
* [https://en.wikipedia.org/wiki/Help:Template Template], Wikipedia help page about templates
{{End Columns}}


[[Category:Help]]
[[Category:Help]]

Revision as of 13:43, 24 April 2024

118Wiki


This is an introduction to templates in 118Wiki.

What is a template?

A template is a piece of code that can be used on multiple pages. A very simple template could be just a string of text, but most of them contain an amount of coding and programming using HTML, CSS, magic words, parser functions and other methods.

Using a template has several advantages, as it cuts down the required effort of having to write or copy the code to each page individually. This is especially important when the code is complicated. If the code needs to be modified, the changes can be done to the template instead of having to look up each page that uses similar code. Additionally, templates help to achieve similar visuals for each page.

Using templates

Template call

The contents of a template can be added (or transcluded) to a page using a template call. A template call is an instruction for the system to search for that template and show its content on the target page when someone is reading it. As such, the template calls are similar to function calls in most programming languages.

In source editing, a template can be called using two curly brackets around the name of the template without the “Template:” prefix. For example, {{Mirror universe}} calls the Template:Mirror universe. It is a template used to inform the readers that the page covers a Mirror universe topic. Below is what it would look like:

This article pertains to a subject of the Mirror universe.Mirror-universe.jpg


In the Visual Editor, you can add a template call to a page by opening the “Insert” menu from the toolbar and clicking “Template”. This will open a dialog box (popup) with a search bar for finding the template. After selecting a template, you may add the template to the page by clicking “Insert” in the top right corner of the dialog box.

Parameters

Templates can also take information the user gives them and change its appearance or functionality depending on the user’s input. For this purpose, the user would use parameters. When calling a template, the user has an option to give a value to a parameter. The value given for a parameter can be text, files, code or even other templates.

In Visual Editor, the dialogue will ask values to each parameter separately. You can choose which parameters you want to use.

In source editing, parameters are separated in the template call by | symbol (vertical bar). Parameters and what they do can typically be found on the template documentation page. There are two types of parameters, named and unnamed.

If the parameter is unnamed, the value given to it is separated from the templates name and other parameters by a vertical bar.

For example, Template:Crewnav can be used on a character page to show the officers who serve on the same ship as that character. Since Template:Crewnav uses a single unnamed parameter, you would give the value with a vertical bar separating it from the template name: {{Crewnav|USS Artemis-A}}. The result is below:

NPC Listing   ·   USS Artemis-A Crew Manifest   ·   Crew History
2400-MacKenzie-WM-Long.png
Commanding Ofc.
Addison MacKenzie
JK - Red Picard v5.jpg
Executive Ofc.
Talos Dakora
Sil-Picard Uniform.png
Chief Tactical Ofc.
Vitor Silveira
Salkath1.png
Engineering Ofc.
Salkath
Imril-Avatar-LD-Style-lores2.png
Engineering Ofc.
Imril
Jovenan Lt 2401.png
Chief Science Ofc.
Jovenan
Lyara.png.a74aa194814329054780237adc48ffdd.png
Helm/Ops Ofc.
Lyara Alroyo
Ollie Bergman Ensign.png
Operations Ofc.
Ollie Bergmen
Ensign Savel.png
Security Ofc.
Savel
Roster-blank.jpg
Security Ofc.
Kel Solas
Gnai.png
Science Ofc.
Gnai
Genkos Adea.png
Chief Medical Ofc.
Genkos Adea
Edit This Nav

A template may sometimes have multiple unnamed parameters. They are separated from each other using the vertical bar. In that case, the parameters always have to be in the same order!

For example, if you want to show one of the ribbons your character has earned, you can use Template:Ribbons. The template requires that you give the name of the ribbon, how large you want the ribbon to be in pixels and how many times the character has earned the ribbon, in this order. So, you could have a template call like {{Ribbons|Innovation Ribbon|120|2}}, with the result:

Award-goldstar.png
Awards ServiceRibbons Innovationribbon 2014.jpg


Example

Tea, Earl Grey, hot

—Jean-Luc Picard

Instead of unnamed parameters, many templates have named parameters. They are also separated from the template name and each other with vertical bars. The parameter’s name is given, after which comes the equality sign =, and lastly the value given to the parameter. For example, if you would want to show a quote someone said, you may use a Template:Quote box with a template call like {{Quote box | quote = Tea, Earl Grey, hot | source = —Jean-Luc Picard | title = Example }}, with the result on the right.

Sometimes you might want to use unnamed parameters out of order. In that case, the ordinal of the unnamed parameter can be used as the parameter name, i.e. the first parameter has the name “1”. As such, the example with the ribbons also works with the code {{Ribbons|2=120|1=Innovation Ribbon|3=2}}.

Learn more

More on the topic

  • Templates, MediaWiki help page about templates
  • Template, Wikipedia help page about templates