Help:Editing/Templates
Templates enable you to do things much faster and/or easier. Templates are used very frequently on pages, so it's best to learn about them. When the wiki sees a template it recognizes on a page, it will automatically replace it with something else. What appears there is up to the users.
How to use a Template
Before a template can be added somewhere, first its contents must be defined on its own page. Template pages should start with the prefix Template:
.
Templates have some limited programming abilities, which gives them lots of possibilities. We'll talk more about those later.
To add a template to a page (which is called transcluding), simply type {{
, the name of the template, and then }}
. If you wish to add any parameters, put a |
between the template's name and the }}
, and define the parameters there. All parameters you define need to be separated by another |
.
ᅠ
Examples
Here's a template where we don't define any parameters, you just drop it right in.
{{example}}
Result: Template:Example
If you visit this template's page, you'll see that its just those five words.
Substitution (for advanced users)
Instead of transcluding a template, one can choose to substitute it. Substitution will replace a template with the contents of the template directly onto the page. To substitute a template, transclude it like you normally would, then add subst:
between {{
and the template's name. After that, click the save button and the wikitext will automatically be added. Do not substitute carelessly, because the substituted wikitext will not be updated when the template is. See Wikipedia:Help:Substitution for more information.
{{subst:delete|This is a bad page.}}
When the page is saved, that text will be replaced with this:
{{DeleteMeta|{{#if: This is a bad page. | This is a bad page. }} }}[[Category:Candidates for deletion]]
Note the automatic forwarding of parameters. When substituting, the page should not appear any differently than it would if transcluded. The only difference is in the page code.
Making Templates
Making a template like Template:Example is rather easy - just type the text you want, and save it. What about ones with parameters?
<!-- -->
) can also be useful.Unnamed Parameters
To add an unnamed parameter, simply put {{{1}}}
where you want it to be.
Here's part of the code for Template:Tip:
Tip:{{{1}}}
If you've seen this template before you know that it has its own special look, but this is all we will look at for now. All the user has to do when transcluding this is enter the text they want:
{{tip|Do not carve without vertex editing afterward.}}
Result:
If you want to add more than one unnamed parameter, simply add another number, increased by 1. For example:
SomeTemplate:{{{1}}} and {{{2}}}
Named Parameters
Usually you would want to have named parameters affect anything only if they are defined when being transcluded. Conditions will be discussed later. For now, let's look at Template:MessageBox, which has some named parameters. In this template, {{{text}}}
marks a place to add wikitext that's defined by |text = Text here
when transcluding.
With named parameter:
{{MessageBox|text=my text}}
Result:
my text |
Without named parameter:
{{MessageBox}}
Result:
{{{text}}} |
Default Value
To make a parameter have a value by default, add a |
to the right of the parameter name, and then define the value. Named and unnamed parameters can use this.
{{{1|3000}}}
This would make the value for 1
3000.
{{{value|}}}
This returns nothing. Without the |
, it would literally return "{{{value}}}" as text, if it hasn't already been defined at some other point.
Documentation
Please give a description of what your template is, and maybe examples. To keep this describing text from appearing on pages, there are 3 different HTML tags you can use.
noinclude
keeps wikitext inside it from appearing on the destination page, while keeping it on the source page.
onlyinclude
makes only wikitext inside it appear on destination pages. Text not inside these will still appear on the template's page.
includeonly
wikitext inside this will not appear on the template page. It has no effect on the destination page however.
They can sound very confusing at first. If you're confused on how to use them, check the source code for a template, because almost all use them for one purpose or another.
Templates not Updating
If you've recently edited a template and the changes are not applying on pages it's been transcluded to, add ?action=purge
at the end of the URL for those pages. This will tell the server to update the page's HTML immediately. You can achieve the same effect by editing a page and saving it without making any changes.
Template Shortcuts
Some templates may have template shortcuts, which are redirects that are abbreviated or otherwise different forms of their target templates. Template shortcuts can be transcluded just like their target templates.
Useful templates
All templates in green text are that color so that they stand out against the greyscale tones of most pages. Most templates with that color also automatically add pages they are transcluded on into Category:TODO.
Bug
Template:Bug notifies readers of a bug.
{{bug|The amount is double what it should be. Be careful!}}
Result:
Bug: The amount is double what it should be. Be careful! |
Clarify
Template:Clarify marks things that should be clarified.
A user module can be created following the usual class creation procedure.{{clarify}}
Result: A user module can be created following the usual class creation procedure.[Clarify]
Cleanup
Template:Cleanup marks a page that needs to be fixed up, preferably by someone knowledgeable. The text message is optional. If you do not give sufficient reason for the notice on the transclusion or the talk page, expect it to be removed by someone else.
{{cleanup|The last section needs to be clarified.}}
Result:
This article needs to be cleaned up to conform to a higher standard of quality because: The last section needs to be clarified.
|
Clr
Template:Clr clears the vertical space to the left or right of something. This is commonly used for making headlines not get moved around by images.
This text should appear next to the image. If you put {{clr}}
right after this,
this bit of text here will get moved down.
This text should appear next to the image. If you put {{clr}}
right after this,
this bit of text here will get moved down.
Delete
Template:Delete marks a page that should be deleted. If you do not give sufficient reason for the notice on the transclusion or the talk page, expect it to be removed by someone else. When putting this on a page, you should also list the reason on that page's talk page, for any future readers that may want to know the purpose of the deletion.
{{delete|This is not a real thing.}}
Result:
This page is a candidate for deletion because: This is not a real thing. If you disagree with its deletion, please explain why on its talk page. Only remove this notice if this page no longer meets the criteria for deletion or you intend to fix it shortly.
|
Ent
Template:Ent is a really small template for making text that's both code and a link.
{{ent|mod}}
Result: Template:Ent
ExpandBox
Template:ExpandBox allows you to hide stuff inside a box that can be shrunk down so that it doesn't make pages as long.
{{ExpandBox|{{:Help:Contents}}}}
Result:
ᅠ
How
Template:How asks the question how?
Players can get past these.{{how}}
Result: Players can get past these.[How?]
Idea
Template:Idea is a nifty way to suggest ideas.
{{idea|Reward players for being clever and creative, instead of forcing things to be only one way.}}
Result:
Merge
Template:Merge is a notice that notifies editors that it's been suggested for two or more pages to be combined into one. All merges should be discussed before being done.
{{merge|HDR}}
Result:
It has been suggested that this article or section be merged with HDR. (Discuss) |
MessageBox
Template:MessageBox provides a standard message box. This template is used by many notice templates, such as merge and cleanup.
{{messageBox|text=Remember to follow wiki etiquette.}}
Result:
Remember to follow wiki etiquette. |
Note
Template:Note is for making notes stand out more.
Bug: Appears to not accept HTML tags inside it...? |
{{note|This will spawn at the map origin if you do not specify the position.}}
Result:
split-apart
Template:SplitApart marks pages that should be split into multiple pages. All splits should be discussed before being done.
{{splitApart}}
Result:
It has been suggested that this article or section be split into multiple articles. (Discuss) |
Stub
Template:Stub marks pages that are very small. See Help:Stubs for info on using.
{{stub}}
Result:
This article or section is a stub. You can help by adding to it. |
Tip
Template:Tip marks text as a tip to readers.
{{tip|This is a much less tricky process when using the vertex edit tool as well.}}
Result:
TocRight
Template:TocRight shifts the table of contents over to the right side of a page.
Todo
Template:Todo marks things that need to be done. It's green color is meant to stand out.
{{todo|Find where this is in the game files.}}
Result: To do: Find where this is in the game files.
Warning
Template:Warning marks things that readers should take caution of when doing something.
{{warning|This tool has been known to corrupt files. Try an alternative listed below.}}
Result:
Why
Template:Why asks the question why?
This shader has been deprecated.{{why}}
Result: This shader has been deprecated.[Why?]
Wip
Template:Wip marks pages that are in the middle of major edits. The adder requests that other users do not edit in the meantime.
{{Wip}}
Result:
This article is actively undergoing a major edit. The user who added this notice will be listed in its edit history should you wish to contact them. |
Magic Words
Magic words are special character strings that are kind of like templates. To apply one, simply type it on the page.
__TOC__
Forces the table of contents to be placed at this spot.
__FORCETOC__
Forces the table of contents to be placed at its normal spot. (Only useful on pages that don't have enough sections to automatically display a TOC.)
__NOTOC__
Hides the table of contents.
__HIDDENCAT__
Marks a category as hidden. To make the website show hidden categories for you, check the Show hidden categories box in Special:Preferences.
{{DISPLAYTITLE:title}}
Changes the title of a page at the top bar only.
See Also
- Special:ExpandTemplates - Shows completely expanded versions of templates, including substituted wikitext code and automatic substitution for any nested templates.
- Special:MostTranscludedPages - Lists templates most frequently used on pages. This doesn't show just templates actually; any page can be transcluded.
- Special:UncategorizedTemplates - Lists templates that are not listed under any categories.
- Special:UnusedTemplates - Lists templates that are not used on any pages.
- Special:WantedTemplates - Lists templates that are frequently used on pages, but do not exist. This list should be showing no pages, ideally.
- Wikipedia:Help:Magic_words_for_beginners - More about magic words.
- Wikipedia:Help:Template - A very helpful resource for template programming.