Help:Templates

From 118Wiki
Revision as of 12:18, 14 May 2024 by Jovenan (talk | contribs) (other pages section; intro redo; - see below for inclusion tags (might make a new page); typos)
Jump to navigation Jump to search
118Wiki


Templates are bits of code that make using the wiki easier. They are used in nearly every page in 118Wiki, including the very basic character pages. This guide explains what the templates are and how to use them on a page.

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
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, 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

Transclusion and substitution

As described above, adding a template to a page using a template call (such as {{Mirror universe}}) is called transclusion. Each time the page is opened, the current form of the template is displayed.

Sometimes, it is more desirable that the display doesn’t change but is static or that it may be modified for the purpose of that one page. The code may be copy-pasted, but this might break it. For example, the inclusion tags should be removed by the user by hand. Instead of copy-pasting, substitution should be used. When the page is saved, substitution replaces the template call with the template code as it would appear had the template merely been transcluded.

For example, if Template:Mirror universe is substituted to a page, the template call would be replaced by the following code:

:''This article pertains to a subject of the [[Mirror universe]].''[[File:Mirror-universe.jpg|x40px|link=Category:Mirror universe]]<br clear=all>

Now, should the template be edited, the display on the page won’t change. Note that the code of the template in its template page has a line <noinclude>[[Category:Mirror universe]]</noinclude>. Since this line is not included in the transclusion, it won’t be in the substitution either.

In source editing, substitution is executed with word subst: in the template call, e.g. {{subst:Mirror universe}}

Many templates call other templates, magic words or parser functions. Substituting a template will only transclude calls in its code. In order to substitute all templates, magic words and parser functions, safe substitution may be used.

In source editing, safe substitution is executed with word safesubst: in the template call, e.g. {{safesubst:Mirror universe}}

Note that substitution and safe substitution will increase the length of the wikicode on page considerably and might make difficult to edit. Some templates are designed so that they are dynamic, so safe substitution in particular may defeat the purpose.

The wikicode of a template may also be called.

In source editing, wikicode call is executed with word msgnw: in the template call, e.g. {{msgnw:Mirror universe}}

Other pages

This help page has concentrated on templates, but everything stated here about templates applies to any other page as well! For example, the contents of an article may be transcluded or substituted to another page. For example, many crew listings depend on character ID pages, such as Tristan Wolf/ID, which doesn’t have the “Template:” prefix and isn’t therefore a template.

When transcluding or substituting a page other than a template, the template call is slightly different in source editing. The prefix “Template:” is left out, but the namespace prefix should be used for any other type of page. For example, this help page is called with {{Help:Templates}}. For main namespace (articles), the namespace prefix is empty, so only a colon : is used, for example {{:Tristan Wolf}} for Tristan Wolf. Substitution of another page works similarly, but with subst: (or equivalent) ahead of the namespace prefix, e.g. {{subst:Help:Templates}} or {{safesubst::Tristan Wolf}}

More on the topic

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