Help:Template

From Homestar Runner Wiki

(Difference between revisions)
Jump to: navigation, search
(Code: rewording)
(Code: sectioning)
Line 8: Line 8:
==Code==
==Code==
 +
 +
=== Creating a template ===
 +
Make sure you know the MediaWiki syntax for a template:
Make sure you know the MediaWiki syntax for a template:
*For an input, type '''<nowiki>{{{1}}}</nowiki>''' for the first input, '''<nowiki>{{{2}}}</nowiki>''' for the second, and so on.
*For an input, type '''<nowiki>{{{1}}}</nowiki>''' for the first input, '''<nowiki>{{{2}}}</nowiki>''' for the second, and so on.
Line 14: Line 17:
**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.
-
Make sure you know how to use the template once it’s been created:
+
=== Including text in a template ===
-
*If the template is in a '''Template:''' namespace, simply type '''<nowiki>{{its name}}</nowiki>''' to use it.
+
-
*If the template is in any other namespace, simply type '''<nowiki>{{Namespace:its name}}</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 include text in the template that you don't want to show up in pages that use it, such as:
To include text in the template that you don't want to show up in pages that use it, such as:
Line 27: Line 25:
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.
-
===Substituting===
+
=== 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 '''<nowiki>{{its name}}</nowiki>''' to use it.
 +
*If the template is in any other namespace, simply type '''<nowiki>{{Namespace:its name}}</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>'''.
 +
 
 +
=== 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, '''<nowiki>{{tick}}</nowiki>''' will display as '''<nowiki>{{tick}}</nowiki>''' in the code, while '''<nowiki>{{subst:tick}}</nowiki>''' will display as '''<nowiki>[[Image:wiki tick.GIF]]</nowiki>''' in the code.
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, '''<nowiki>{{tick}}</nowiki>''' will display as '''<nowiki>{{tick}}</nowiki>''' in the code, while '''<nowiki>{{subst:tick}}</nowiki>''' will display as '''<nowiki>[[Image:wiki tick.GIF]]</nowiki>''' in the code.

Revision as of 21:50, 23 October 2006

Here's how to create and use a template:

Usage

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

Code

Creating a template

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.
    • This can also be substituted with {{{value}}} or another name.
  • For current page information, type {{NAMESPACE}} for the page’s namespace, and {{PAGENAME}} for the page’s name.
    • These will be inserted and changed as the location of the template changes.

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.

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 {{its name}} to use it.
  • If the template is in any other namespace, simply type {{Namespace:its name}} to use it.
  • For an input, {{{1}}}, type {{its name|input 1|input 2|etc...}}.
  • For an input, {{{value}}}, type {{its name|value = input 1}}.

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, {{tick}} will display as {{tick}} in the code, while {{subst:tick}} will display as [[Image:wiki tick.GIF]] in the code.

Example

Here is a simple example, creating a signature for any user typing {{Sig|User}}:

If the template contains the code:
[[User:{{{1}}}|{{{1}}}]] ([[User talk:{{{1}}}|talk]] · [[Special:Contributions/{{{1}}}|edits]])
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)
Personal tools