Changes

7,366 bytes added ,  10:05, 13 March 2018
m
1 revision imported: Resources from GCPedia
{{GC2.0 Tools Help gcp}}
{{TOCleft}}

{{help TOC}}__NOTOC__ 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 [[GCPEDIA:Template namespace|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 [[Special:MostLinkedTemplates|most frequently used templates]] on GCpedia, and the user community maintains an inventory of [[Help:Notice templates|notice templates]] that go at the top of articles, [[UBX|userboxes]] which are used on user pages, and a general index of [[GCPEDIA:Template inventory|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 <code><nowiki>{{Template name}}</nowiki></code> 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 <code><nowiki>{{Template_Name}}</nowiki></code> is typed; this will cause the content of the template page to appear in the wiki page at the place where <code><nowiki>{{Template_Name}}</nowiki></code> appears in the wiki-text. Should the template change, its appearance on all pages that use it in this way will also change accordingly. <!--
===Useful pre-fabricated GCPEDIA templates===
* {{tl|Archive}} - insert this banner template indicating the need to archive information
* {{tl|Cleanup}} - insert this template to indicate that the wiki page needs be better organized, better formatted, etc
* {{tl|Delete}} - insert this template to indicate a delete request for a particular wiki page (''see also [[Help:Delete]''])
* {{tl|Naming}} - insert this template to indicate the page needs to be renamed
* {{tl|Work In Progress}} - insert this template to indicate the page may show some broken code, unfinished formatting, etc.
-->

== Substitution ==

This method is used by typing <code><nowiki>{{subst:Template_Name}}</nowiki></code> 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 <code><nowiki>{{subst:Template_Name}}</nowiki></code> 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: {{tl|basic user profile}}, {{tl|deluxe user profile}}, {{tl|sample community page}}, and {{tl|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 {{tl|ambox}}.

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

<nowiki>{{ambox
| type = notice
| text = The message body text.
}}</nowiki>


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

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

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 {{tl|userbox3}}.

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

<nowiki>
{{userbox3|{{{1}}}|{{{2}}}|{{{3}}}|{{{4}}}|{{{5}}} }}
</nowiki>


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:

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


Produces: {{userbox3|red|white|gold|[[image:gnome.png|40px]]|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 <code><nowiki>{{Name of my template}}</nowiki></code>. It will appear as a broken (red) link, for example {{Name of my template}}. 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 <code>"Template:Name of my template"</code> 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 <code><nowiki>{{Name of my template}}</nowiki></code> where you want it to appear on the page. To transclude your template, include <code><nowiki>{{subst:Name of my template}}</nowiki></code> 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 ==

*[[Help:Notice Templates]]
*[[GCPEDIA:Template namespace]]

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

*[[Special:PrefixIndex/Template:|All templates in GCPEDIA]]

== External links ==

*[http://en.wikipedia.org/wiki/Help:Template Wikipedia - Help:Templates]
*[http://en.wikipedia.org/wiki/Help:A_quick_guide_to_templates Wikipedia - A quick guide to templates]
*[http://en.wikipedia.org/wiki/Help:Advanced_templates Wikipedia - Help: Advanced templates]

[[Category:GCPEDIA_Help]]
[[fr:Aide:Modèles|fr:Aide:Modèles]]