Important: The GCConnex decommission will not affect GCCollab or GCWiki. Thank you and happy collaborating!

Difference between revisions of "Help:Templates"

From wiki
Jump to navigation Jump to search
m (1 revision imported: Resources from GCPedia)
(No difference)

Revision as of 10:05, 13 March 2018

GCTools Help Centre

Home
GCpedia
GCconnex
GCpedia Help
Get help
Contact GCpedia admin
admin.GCpedia@tbs-sct.gc.ca

A template is a wiki page which is created to be included on other pages. Template pages are created and edited just like other pages on GCpedia, except that they are created in the Template namespace.

Templates usually contain repetitive material that might need to show up on several wiki pages. They are commonly used for boilerplate messages, standard warnings or notices, infoboxes, navigational boxes and similar purposes. GCpedia generates a dynamic list of the most frequently used templates on GCpedia, and the user community maintains an inventory of notice templates that go at the top of articles, userboxes which are used on user pages, and a general index of other templates.

By using a template the content can be present on as many articles as necessary and if it is edited the changes will be reflected everywhere it appears.

Use of a template can be generalized into two different ways: transclusion and substitution. The two have very different functions and in most cases one will be clearly more useful than the other depending on what is required.

The most common method of template use is transclusion, where the wikitext of the target page contains a reference to the template, using the {{Template name}} syntax. Substitution is where the content of the template is copied into the wikitext of the target page, just once, when it is saved.

Transclusion

Transclusion is the 'default' method of using templates, meaning it is the method that will be chosen by the wiki software when {{Template_Name}} is typed; this will cause the content of the template page to appear in the wiki page at the place where {{Template_Name}} appears in the wiki-text. Should the template change, its appearance on all pages that use it in this way will also change accordingly.

Substitution

This method is used by typing {{subst:Template_Name}} where you want the contents of the template to appear. This will cause the wiki-text present in the template to be copied into the page at the point where {{subst:Template_Name}} was typed. This is most useful when creating new pages of a type for which a template exists, or perhaps to insert some recurring wiki-text that would otherwise take considerably longer to type every time.

Creating a template for Substitution purposes does not need any special wiki-text and can be easily accomplished by anyone who can edit this wiki. This is generally used as a guideline for layout of a type of page, helping people who would want to contribute by having the wanted layout prepared, needing nothing more than a simple 'fill-in-the-blanks' type of editing.

Examples of commonly used substitution templates include: {{basic user profile}}, {{deluxe user profile}}, {{sample community page}}, and {{Two column fr-en}}.

Advanced uses

For more advanced uses, templates can use variables (parameters) when they are used on a page. An example of a template that uses variables is the generic {{ambox}}.

To use such a template, the variables must be assigned values when it is placed on a page. Using the example of {{ambox}} the variables can be given values such as:

{{ambox
| type      = notice
| text      = The message body text.
}}

Where "type" is a variable with the value "notice" and "text" is a variable with the value "The message body text".

This gives:


Some templates have variables that are not names, but numbers, such as {{{1}}}, which only requires a value to be given, and the placeholders will be replaced. An example of a template that uses numbered values is the generic {{userbox3}}.

Before assigning values to {{userbox3}} it looks like this:

{{userbox3|{{{1}}}|{{{2}}}|{{{3}}}|{{{4}}}|{{{5}}} }}
 

Where {{{1}}} = left colour, {{{2}}} = right colour, {{{3}}} = border colour, {{{4}}} = image, and {{{5}}} = text.

Replacing the numbered variables with values like in the example below:

{{userbox3|red|white|gold|[[image:gnome.png|40px]]|A userbox is a small rectangular box that looks like this.}}
 

Produces:

Gnome.png A userbox is a small rectangular box that looks like this.


Template documentation

Most templates on GCpedia have documentation that has been written to describe their usage and any variables that may be defined. It is good practice to read the documentation for a template in order to better understand how they are meant to be used.

Creating and editing templates

Any GCpedia user can create a template. To create a template add a line to your article that looks like this {{Name of my template}}. It will appear as a broken (red) link, for example . Clicking on it will take you to the template page and you can now add the content for the template. This is the same method used to create any page on GCPEDIA. An alternative method is to search for the name of your desired template in the search box making sure to include the prefix "Template:". For example, searching for "Template:Name of my template" will also work.

Once you have created your template page, add content to it by editing it the same as you would do for any page on GCpedia.

To transclude the content of your template to any page you now just need to include {{Name of my template}} where you want it to appear on the page. To transclude your template, include {{subst:Name of my template}} where you want it to appear on the page.

Be extremely careful when editing existing templates – changes made can affect a large number of pages, in ways you might not expect.

Internal links

To see a full listing of templates, click on a letter of interest.

External links