Help:Templates

From 118Wiki
Jump to navigation Jump to search
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 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 your input. For this purpose, you would use parameters. When calling a template, you have 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
Hallia Yellir Picard Uniform.png
Chief Eng. Ofc.
Hallia Yellir
Salkath.jpg
Engineering Ofc.
Salkath
Jeseb Chevalier Ensign.png
Operations Ofc.
Jaseb Chevalier
Ensign Savel.png
Security Ofc.
Savel
Roster-blank.jpg
Security Ofc.
Kel Solas
Jovenan LtJG 2400.png
Chief Science Ofc.
Jovenan
Gnai.png
Science Ofc.
Gnai
Genkos Adea.png
Chief Medical Ofc.
Genkos Adea
Sadar-2400.png
Medical Ofc.
Gila Sadar
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, followed by 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