Help:Template

From Homestar Runner Wiki

(Difference between revisions)
Jump to: navigation, search
(Shortcuts: more)
(No need for a __FORCETOC__ anymore)
 
(includes 13 intermediate revisions)
Line 1: Line 1:
-
__FORCETOC__
 
-
 
Wiki users can '''create and use templates'''. A template is a bit of code which any user can insert into any page of the wiki, to create a larger displayed piece of text which can be specialized for that inclusion. The template is created with both static text and variables such as "inputs" and "values". Here's the basics on how to create and use templates.
Wiki users can '''create and use templates'''. A template is a bit of code which any user can insert into any page of the wiki, to create a larger displayed piece of text which can be specialized for that inclusion. The template is created with both static text and variables such as "inputs" and "values". Here's the basics on how to create and use templates.
== Creating a template ==
== Creating a template ==
-
[[HRWiki:Template messages]] is a list of existing templates. Please check there to be sure your idea for a template has not been done yet.
+
[[HRWiki:Template messages|The template messages page]] contains a partial list of existing templates. Please check that page to be sure your idea for a template has not been done yet.
=== Usage ===
=== Usage ===
Line 18: Line 16:
*For an input, type '''<nowiki>{{{1}}}</nowiki>''' for the first input, '''<nowiki>{{{2}}}</nowiki>''' for the second, and so on. The user of the template will need to know which order the items should be listed when using the template.
*For an input, type '''<nowiki>{{{1}}}</nowiki>''' for the first input, '''<nowiki>{{{2}}}</nowiki>''' for the second, and so on. The user of the template will need to know which order the items should be listed when using the template.
**In a more complicated template, where one might not easily remember the order of which input is which, this can be substituted with '''<nowiki>{{{value}}}</nowiki>''' or another more meaningful name, like '''<nowiki>{{{name}}}</nowiki>''' or '''<nowiki>{{{old page}}}</nowiki>'''. These can be used in any order, unlike numeric values.
**In a more complicated template, where one might not easily remember the order of which input is which, this can be substituted with '''<nowiki>{{{value}}}</nowiki>''' or another more meaningful name, like '''<nowiki>{{{name}}}</nowiki>''' or '''<nowiki>{{{old page}}}</nowiki>'''. These can be used in any order, unlike numeric values.
-
*For current page information, type '''<nowiki>{{NAMESPACE}}</nowiki>''' for the page’s namespace, and '''<nowiki>{{PAGENAME}}</nowiki>''' for the page’s name.
+
*For current page information, type '''<nowiki>{{NAMESPACE}}</nowiki>''' for the page’s namespace, and '''<nowiki>{{PAGENAME}}</nowiki>''' for the page’s name. If you want both, type '''<nowiki>{{FULLPAGENAME}}</nowiki>'''.
**These will be inserted and changed as the location of the template changes.
**These will be inserted and changed as the location of the template changes.
Line 28: Line 26:
Place the text in a set of '''<nowiki><noinclude></nowiki>''' tags at the bottom of the template page.
Place the text in a set of '''<nowiki><noinclude></nowiki>''' tags at the bottom of the template page.
 +
 +
=== Text that will only be included in the target page ===
 +
 +
To include text in the pages that use the template, but not the template page itself, such as:
 +
 +
*A category relevant to the page in question, but not the template itself.
 +
*Special Formatting text meant only for the page in question.
 +
 +
Place the text in a set of '''<nowiki><includeonly></nowiki>''' tags around the text in question.
== Using a template ==
== Using a template ==
Make sure you know how to use the template once it’s been created:
Make sure you know how to use the template once it’s been created:
-
*If the template is in a '''Template:''' namespace, simply type '''<nowiki>{{its name}}</nowiki>''' to use it.
+
*If the template is in a '''Template:''' namespace, simply type '''<nowiki>{{templatename}}</nowiki>''' to use it.
-
*If the template is in any other namespace, simply type '''<nowiki>{{Namespace:its name}}</nowiki>''' to use it.
+
*If the template is in any other namespace, simply type '''<nowiki>{{Namespace:templatename}}</nowiki>''' to use it.
-
*For an input '''<nowiki>{{{1}}}</nowiki>''', type '''<nowiki>{{its name|input 1|input 2|etc...}}</nowiki>'''.
+
 
-
*For an input '''<nowiki>{{{value}}}</nowiki>''', type '''<nowiki>{{its name|value = input 1}}</nowiki>'''.
+
To add custom inputs to the rendering of the template, follow these simple instructions.
 +
*For an input '''<nowiki>{{{1}}}</nowiki>''' or '''<nowiki>{{{2}}}</nowiki>''' etc., type '''<nowiki>{{templatename|input_1|input_2|etc...}}</nowiki>'''.
 +
*For an input '''<nowiki>{{{value}}}</nowiki>''', type '''<nowiki>{{templatename|value = input_for_value}}</nowiki>'''.
=== Substituting text for template ===
=== Substituting text for template ===
Line 68: Line 77:
==Shortcuts==
==Shortcuts==
 +
Many commonly-used templates have shortcut versions which you can use. Here is a partial list.
-
{{sectionstub}}
+
*{{tl|delete}} - {{tl|d}}
-
 
+
*{{tl|tobediscussed}} - {{tl|tbd}}, {{tl|tobedeleted}}, {{tl|talktobedeleted}}, {{tl|ttbd}}, {{tl|merge}}, {{tl|m}}, {{tl|move}}, {{tl|redirect}}, {{tl|r}} (these were formerly separate functions that have since been combined)
-
Many commonly-used templates have shortcut versions which you can use. Here is a partial list.
+
*{{tl|plainlinks}} - {{tl|p}} or {{tl|pl}}
 +
*{{tl|tl}} - {{tl|t}} (for links to template pages)
-
*[[Template:merge|<nowiki>{{merge}}</nowiki>]] - <nowiki>{{m}}</nowiki>
+
==See Also==
-
*[[Template:plainlinks|<nowiki>{{plainlinks}}</nowiki>]] - <nowiki>{{p}}</nowiki>
+
*[[:Category:HRWiki Templates]] - A categorized listing of all templates available for use in this wiki.
-
*[[Template:tobedeleted|<nowiki>{{tobedeleted}}</nowiki>]] - <nowiki>{{tbd}}</nowiki>
+
-
[[Category:Help|T]]
+
[[Category:Help|{{PAGENAME}}]]

Current revision as of 20:30, 14 February 2009

Wiki users can create and use templates. A template is a bit of code which any user can insert into any page of the wiki, to create a larger displayed piece of text which can be specialized for that inclusion. The template is created with both static text and variables such as "inputs" and "values". Here's the basics on how to create and use templates.

Contents

[edit] Creating a template

The template messages page contains a partial list of existing templates. Please check that page to be sure your idea for a template has not been done yet.

[edit] Usage

First, consider what the template would be used for. What would its purpose be? Some common uses are:

[edit] Syntax

Make sure you know the MediaWiki syntax for a template:

  • For an input, type {{{1}}} for the first input, {{{2}}} for the second, and so on. The user of the template will need to know which order the items should be listed when using the template.
    • In a more complicated template, where one might not easily remember the order of which input is which, this can be substituted with {{{value}}} or another more meaningful name, like {{{name}}} or {{{old page}}}. These can be used in any order, unlike numeric values.
  • For current page information, type {{NAMESPACE}} for the page’s namespace, and {{PAGENAME}} for the page’s name. If you want both, type {{FULLPAGENAME}}.
    • These will be inserted and changed as the location of the template changes.

[edit] Including text in a template

To include text in the template that you don't want to show up in pages that use it, such as:

  • Instructions on how to use the template
  • A category to organize the template

Place the text in a set of <noinclude> tags at the bottom of the template page.

[edit] Text that will only be included in the target page

To include text in the pages that use the template, but not the template page itself, such as:

  • A category relevant to the page in question, but not the template itself.
  • Special Formatting text meant only for the page in question.

Place the text in a set of <includeonly> tags around the text in question.

[edit] Using a template

Make sure you know how to use the template once it’s been created:

  • If the template is in a Template: namespace, simply type {{templatename}} to use it.
  • If the template is in any other namespace, simply type {{Namespace:templatename}} to use it.

To add custom inputs to the rendering of the template, follow these simple instructions.

  • For an input {{{1}}} or {{{2}}} etc., type {{templatename|input_1|input_2|etc...}}.
  • For an input {{{value}}}, type {{templatename|value = input_for_value}}.

[edit] Substituting text for template

For some templates, it is a better idea to take load off the server and use subst: before the template name. This substitutes the dynamic code on the page with static text. For example, just typing {{tick}} will result in {{tick}} being added to the code, while typing {{subst:tick}} will result in, say, [[Image:wiki tick.GIF]] (or whatever the template's results are) being added to the code. Both will appear the same to the reader, but the latter one does not call up the template every time.

[edit] Example

Here is a simple example, creating a signature for any user typing {{Sig|User}}. (Note: This already exists as Template:user. There's no need to recreate this template again, this is just an example.)

First, let's say we want to have the result take the form "User (talk · edits)" where we link each word to the user's userpage, his talk page, and his contributions listing respectively.

As the user is putting their user name in as input 1, we can create a link to their userpage this way:

[[User:{{{1}}}|{{{1}}}]]

Similarly, a link to their talk page can be done like this:

[[User talk:{{{1}}}|talk]]

The way to do a link to the user's contributions is:

[[Special:Contributions/{{{1}}}|edits]]

So if the template contains the code:

[[User:{{{1}}}|{{{1}}}]] ([[User talk:{{{1}}}|talk]] · [[Special:Contributions/{{{1}}}|edits]])

then typing {{Sig|user}} inserts this code:

[[User:User|User]] ([[User talk:User|talk]] · [[Special:Contributions/User|edits]])

which shows on the page as:

User (talk · edits)

[edit] Shortcuts

Many commonly-used templates have shortcut versions which you can use. Here is a partial list.

[edit] See Also

Personal tools