Help:Templates
That means that this article contains information intended to advise or aid on the functions of the wiki, on how to use the wiki, or on general recommendations for users of the wiki.
For help, see the VDC Editing Help and Wikipedia cleanup process. Also, remember to check for any notes left by the tagger at this article's talk page.
A template is a wiki page created to be included in other pages. Templates usually contain repetitive material that might need to show up on a larger number of articles or pages. They are commonly used for boilerplate messages, standardized warnings or notices, infoboxes, navigational boxes, and similar purposes.
They 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
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 |
.
{{:Main Page}}
, but we don't do this here because it would add all of the headlines of the Main Page to the table of contents of this page.Examples
Here’s a template where we don’t define any parameters. When previewing, the expression {{Restart}}
(or {{restart}}
) will be replaced with the content of the page Template:Restart. If you visit it, you’ll see that it contains just those five words.
{{Restart}}
→ Requires restart to take effect.
sv_cheats
console command, which is wrong, because it is not an entity. Please use {{Command}}
for console commands.{{Ent}}
can accept up to two unnamed parameters. As described on its page, the template works in a way that it will display the value of the first parameter in a monospace font and also making it a wikilink. Suppose we want a code style link to sv_cheats; To use this template, we type {{, followed by the template name which is ent or Ent, then for the first parameter we type a pipe and the value sv_cheats. If we want to, we can also specify a second parameter which (as the template specifies) will also be displayed in code style but not as a link. The order of unnamed parameters matters. If we specify no parameter, the template doesn't work as intended.
Template:KV is one of the most common templates used to display information about a keyvalue of an entity class. It accepts multiple optional named parameters such as only
and nofgd
. To specify a value for those, we need to type the name of the parameter, an equals sign and then the value. Named parameters can be defined in any order. Note that we can specify both unnamed and named parameters. In the following example, we have three unnamed parameters (ammo, integer and the last one) and two named parameters (only={{css}} and nofgd=1).
{{KV
|only={{css}}
|ammo
|nofgd=1
|integer
|Amount of reserve ammo to be added. Fallback value is 0.
}}↓
Without the |nofgd=1
, the !FGD part would not have displayed.
{{Ent|2=1
|1=sv_cheats
}}
→ sv_cheats 1
. In fact, unnamed parameters do have a name they can be defined with, namely their parameter number. This way one could also for example specify a third parameter but not a first and second.Templates can also use templates, named nesting. Recursion is not supported, so a template cannot use itself.
Substitution
This is for advanced users. Instead of transcluding a template, one can choose to substitute it. Substitution will replace the wikitext of a template call with the contents of the template. Do not substitute carelessly, because the substituted wikitext will not be updated when the template is. See Wikipedia:Help:Substitution for more information.
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.
For example, if you write {{Restart}}
on a page, save it, and edit the page again, you will still find {{Restart}}
at the same place in the wikitext. In contrast, if you save {{subst:restart}}
and edit the page again, you'll find Requires restart to take effect.
instead. It can be imagined that the wiki "copy-pastes" the content over, but it does regard parameter values:
{{subst:delete
|This is a bad page.
}}
If a page is saved with this, that text will be replaced with the content of Template:Delete where every occurrence of {{{1}}} is replaced with This is a bad page.
:
{{Delete-meta|{{#if: This is a bad page. | This is a bad page. }} }}[[Category:Candidates for speedy 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
Before a template can be added somewhere, first its contents must be defined on its own page. Template pages start with the prefix Template:
. See also: Help:Page Creation.
Making a template like Template:Restart is rather easy: Enter Template:Restart in the search bar in the top right, click on its red link (assuming the page doesn't exist yet), type the text you want, and save it. After that, this new template can be used as described above.
<!-- -->
) can also be useful.Unnamed Parameters
To add an unnamed parameter, simply put {{{1}}} wherever you want the value of the first unnamed parameter to be. Here's a 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.
}}↓ Tip:Do not carve without vertex editing afterward.
If you want to add more than one unnamed parameter, simply change the number. Here's the old (condensed) code for Template:Distinguish. This template has some things we haven't talked about yet, but you can still see that there's four unnamed parameters used: {{{1}}}, {{{2}}}, {{{3}}}, and {{{4}}}.
:''Not to be confused with [[:{{{1}}}]]{{#if:{{{2|}}} |{{#if:{{{3|}}} |, [[:{{{2}}}]]| or [[:{{{2}}}]].}}|.}}{{#if:{{{3|}}} |{{#if:{{{4|}}} |, [[:{{{3}}}]]|, or [[:{{{3}}}]].}}}}{{#if:{{{4|}}} |, or [[:{{{4}}}]].}}''
All the user has to do when transcluding is this:
{{Distinguish
|Combine
|Civil Protection
|Overwatch
}}↓
Named Parameters
Usually you would want to have named parameters affect anything only if they are defined when being transcluded. We'll talk about conditions later. For now, let's look at Template:IO, which has many named parameters. In this template, {{{param}}} marks a place to add wikitext that's defined by |param=texthere
when transcluding.
With named parameter:
Without named parameter:
{{IO
|SetString
|Updates the string.
}}↓ SetString
- Updates the string.
Example of unnamed:
{{Note| test }}
result:
test
Example of named:
{{Note|1 = test }} result:
Default Value
To make a parameter have a value by default, add a |
to the right of the parameter name, and then define the default value. Both named and unnamed parameters can use this.
This would set the value for {{{1}}} to 3000 if the user does not specify it.
This returns the empty string if the user does not specify |value=...
. Note the difference between {{{value}}} and {{{value|}}}. The former would literally return the text {{{value}}}
if the user doesn't define it.
Parser Functions
To make text (dis)appear only if a certain parameter is defined or set to a specific value, the following expressions are the way to go.
The parser function #if:
checks if a string is empty or not. The syntax is {{#if: <string> | <then> | <else> }}
. This expression evaluates to <then>
iff <string>
is not the empty string, otherwise to <else>
. The <else>
value can be omitted in which case it defaults to the empty string; The same applies to the following <else>
s.
{{#if: | Not empty | Empty }}
→ Empty{{#if: X | Not empty | Empty }}
→ Not empty{{#if: | Not empty }}
→{{#if: X | Not empty }}
→ Not empty{{#if: {{{target|}}} | Target aqcuired | Sleep mode activated... }}
→ Sleep mode activated...{{#if: Something is there! | Target aqcuired | Sleep mode activated... }}
→ Target aqcuired
{{{target|}}}
returns the empty string because you (probably) are not viewing this page through a transclusion, so it's never had a chance to be defined and thus returns its default value being the empty string.#ifeq:
checks for equality between two strings. The syntax is {{#ifeq: <string1> | <string2> | <then> | <else> }}
. This evaluates to <then>
iff the two (trimmed) strings are entirely equal, otherwise to <else>
.
{{#ifeq: X | X | Equal | Not equal }}
→ Equal{{#ifeq: X | Y | Equal | Not equal }}
→ Not equal{{#ifeq: {{{target|}}} | friend | Friend... | Go away! }}
→ Go away!{{#ifeq: friend | friend | Friend... | Go away! }}
→ Friend...
#switch:
checks for equality between an input string and multiple strings. The syntax is
{{#switch: <input> | <string1> = <value1> | <string2> = <value2> | ... | #default = <default> }}
.
This statement evaluates to the corresponsing <valueX>
of the first <stringX>
that equals the <input>
. If that <stringX>
is not followed by an equals sign such that there is no <valueX>
, then the <valueY>
of the next <stringY>
that does have an equals sign is used instead. If no equality is found, <default>
is returned which defaults to the empty string if not specified.
#expr:
solves math problems. See Help:Calculation for all it's abilities. If an error occurs, a string within a <strong class="error">
element is returned.
{{#expr: 2 + 2}}
→ 4{{#expr: cos(pi/3)^2}}
→ 0.25{{#expr: 0 and 1 or 1}}
→ 1{{#expr: 1 + }}
→ Expression error: Missing operand for +.{{#ifeq: {{#expr: 1 + }} | 1 | True | False}}
→ False
#ifexpr:
tests whether a math expression is true or false and can returns different values depending on it.
{{#ifexpr: 6 + 3 = 9 | Right | Wrong }}
→ Right{{#ifexpr: 6 + 3 = 63 | Right | Wrong }}
→ Wrong
.
is converted to the same zero as 0.
.For example, use {{{hl2|0}}}.
instead of {{{hl2|0}}}
because the latter may fail if hl2=
is specified:
{{#ifexpr: 1 or . | True | False}}
→ True{{#ifexpr: 1 or | True | False}}
→ Expression error: Missing operand for or.
lc:
and uc:
convert a string to lower case or upper case. Note that these don't have a hash sign as opposed to #if:
and so on.
There is also lcfirst:
and ucfirst:
that only manipulate the first character of the expression.
{{lc:Case Sensitivity}}
→ case sensitivity{{uc:Case Sensitivity}}
→ CASE SENSITIVITY{{lcfirst:Case Sensitivity}}
→ case Sensitivity
Documentation
Please give a description of what your template does, and especially examples. To keep describing text from appearing on pages that use the template or to make the template page itself look cleaner, there are three different HTML tags you can use.
<noinclude>...</noinclude>
prevents wikitext from from being transcluded to other pages. It will show only on the template's page.<onlyinclude>...</onlyinclude>
makes only wikitext inside it appear on destination pages. Everything else is not transcluded but will still appear on the template's page.<includeonly>...</includeonly>
prevents wikitext inside from appearing on the template's page. It has no effect on the destination page.
So you can either surround everything that should be transcluded with <onlyinclude>
or surround everything else with <noinclude>
. In addition, you can use <includeonly>
to hide the template text on the template page.
The tags 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.
If the documentation cannot be kept short, then it is a good idea to move all explanations and/or examples to an own page. By convention, the documentation page of a template should be its subpage /doc
. For instance, Template:Note has its documentation page Template:Note/doc. When created, the documentation is transcluded to the template page using just the expression {{Doc}}
which of course must be excluded using the above tags.
Sometimes, templates are used identically. As you might know, Template:Tip and Template:Note both use their one parameter in exactly the same manner, so there is no need for another page with an identical documentation for Tip. Tip can use the same documentation as Note using the expression {{Documentation
; The only magic behind this is that Template:Note/doc uses the expression |Template:Note/doc
}}{{ROOTPAGENAME}}
instead of Note
for its examples so that the examples adapt to the page that they are displayed on. If Template:Note/doc wasn't made for this, this wouldn't work out.
Other "generic docs" like this that are in use are Template:Hl2 and Template:Yes.
Templates not updating
If you've recently edited a template and the changes are not applying on pages that 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.
If you're on a template page with a documentation, you can also use the "[purge]" button for the same effect.
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.
Translations
Templates should include translations so that people who natively speak other languages can more easily understand the contents of the template. There are two ways this can be accomplished.
Method One: #switch: {{language}}
This is usually used on smaller templates with little text. This switch automatically detects the language based on what page it's on (see {{language}}
) and gives the appropriate translation, if available. This is usually sufficient, however on larger templates it is usually recommended to use Method Two.
Method Two: Strings Subpage
Larger templates (e.g. {{Software page}}
) tend to have large amounts of text, and having them all on one page makes it pointlessly cluttered and very hard to edit. To solve this, almost all text on these templates go on a Strings Subpage (e.g. {{Software page/strings}}
), which, when a specific string is specified, will present the appropriately translated text. This helps make not only text editing but translating much easier because editors don't have to shift through lots of code to find a small bit of text they want to edit/translate. This can he very complicated for smaller templates however, so it is usually reserved for larger 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.
Per-game Templates
All games have templates named by their shortcut that can deliver their associated icon and/or a link to their page. See Category:Game icons for a full list of game shortcuts. All of them accept the same set of parameters that are described on every template page. The following table should give examples and also give ideas on when to use them.
Wikitext | Example | Description | Formerly used template/Alternatives | ||
---|---|---|---|---|---|
{{<shortcut>}} |
{{Hl2}} |
→ | Displays the game's icon which links to its game's page and shows the game's name as a hover text. Putting this at the beginning (or end) of a word or line is the shortest and most common way of clarifying that something applies only to a specific game, but there are more ways. | ||
{{<shortcut> |
{{Hl2 |
→ | Half-Life 2 | Displays the game's icon followed by its name which both link to the game's page. Useful in sentences when the icon alone is too little but the next style is too much. | {{Game link}} [ Deprecated]
|
{{<shortcut> |
{{Hl2 |
→ | Half-Life 2 | Does the same but using colorful text which grabs more attention, so don't overuse this on a page. Especially if you name the same game multiple times in a text, you definitely don't need a long, colorful link every time, let alone a link. | |
{{<shortcut> |
{{Hl2 |
→ | (in ) | Can be used to indicate that something applies to a specific game. Useful at the end of a line or key word; The same applies to the following variants. | {{In}}
|
{{<shortcut> |
{{Portal2 |
→ | (in all games since ) | Can be used to quickly note features that were added in a game and are available in all Source games afterwards. | {{Since}}
|
{{<shortcut> |
{{Csgo |
→ | (only in ) | Indicates features that are exclusive to a specific game. | {{Only}}
|
{{<shortcut> |
{{As {{Gmod |
→ | (in all games since ) (also in ) | Notes that earlier game also has a feature, usually backported from newer engine branches. These should be used with in conjunction with another game notice template. | {{Also}}
|
{{<shortcut> |
{{L4d |
→ | (removed since ) | Indicates that a feature was removed in a game and all later engine branches. | {{Removed}}
|
{{<shortcut> |
{{Czds |
→ | (not in ) | Indicates that a feature might be in other games but not in a specific one. | {{Not}}
|
Inline Note Templates
The following are some of the inline note templates.
Description | Wikitext and Result |
---|---|
Template:Bug notifies readers of a bug. | {{Bug Bug:The amount is double what it should be. Be careful! [todo tested in?] |
Template:Clarify marks things that should be clarified. | PAS is a kind of bounding-box for Player or NPC AI sound detection. PAS is a kind of bounding-box for Player or NPC AI sound detection.[Clarify] |
Template:Confirm marks something that needs to be confirmed. It's green color is meant to stand out. | {{Confirm Confirm:Always goes to the left. |
Always goes to the left. Always goes to the left.[confirm] | |
Template:Distinguish lets you notify users about pages that share similar names or may be confused for something else. | {{Distinguish Not to be confused with "Follow Freeman!" (The HL2 chapter).
|
Template:How asks the question how? | Players can get past these. Players can get past these.[How?] |
Template:Idea is a nifty way to suggest ideas. | {{Idea Idea:Reward players for being clever and creative, instead of forcing things to be only one way.
|
Template:Main notes that there is a more detailed article about a certain topic. | {{Main Main article: Soundscripts
|
Template:Note is for making notes stand out more. | {{Note Note:This will spawn at the map origin if you do not specify the position.
|
Template:Question denotes a question | {{Question Question: Does this work in newer engine branches?
|
Template:Suggestion is for suggesting something | {{Suggestion Suggestion: Levels should be optimized for peak performance.
|
Template:Tip marks text as a tip to readers. | {{Tip Tip:This is a much less tricky process when using the vertex edit tool as well.
|
Template:Todo marks things that need to be done. It's green color is meant to stand out. | {{Todo To do: Find where this is in the game files. |
Template:Warning marks things that readers should take caution of when doing something. | {{Warning Warning:This tool has been known to corrupt files. Try an alternative listed below.
|
Template:Workaround informs readers of a workaround | {{Workaround Workaround:This should be automated with logic instead.
|
Template:Why asks the question why? | This shader has been deprecated. This shader has been deprecated.[Why?] |
Notice Templates
The following is a list of some notice templates.
Description | Wikitext and Result |
---|---|
{{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 This article or section needs to be cleaned up to conform to a higher standard of quality because: The last section needs to be clarified For help, see the VDC Editing Help and Wikipedia cleanup process. Also, remember to check for any notes left by the tagger at this article's talk page. |
{{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 help page has been marked as a candidate for speedy deletion. If you object to this decision, then please discuss why here (If you make a discussion section also create this redirect page). If this page doesn't meet the criteria for speedy deletion, then please remove this notice, but do not remove it from pages that you have created yourself Administrators / Moderators - Remember to check if anything links here and the page history before deleting. |
{{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 |
{{Split-apart}} marks pages that should be split into multiple pages. All splits should be discussed before being done.
|
{{Split-apart}}
|
{{Moveto}} marks pages that should be moved to a different title, or sections of an article that should be moved to either another article or to their own new one. All moves should be discussed before being done.
|
{{Moveto}}
|
{{Screenshot}} marks pages that should have more images on them. It allows for an optional text message to clarify what needs images.
|
{{Screenshot}} This article or section needs a screenshot to help visually convey the subject. You can upload screenshots at Special:Upload. For help, see Help:Images.
|
{{Obsolete}} marks things that should no longer be used. Accepts three parameters, entity, tool, and shader.
|
{{Obsolete This entity is obsolete; its use is discouraged and it may only exist/function in older engine branches.
|
{{Spammer}} marks users that should be banned for spamming. For suspicious but not bannable behavior, there is also Template:Minor Spammer. Bug:This template's formatting may look weird sometimes. It's intended to be the only thing on a page. [todo tested in?] |
{{Spammer}}
|
{{Banned user}} marks users that have been banned (usually by Valve employees) for spamming, vandalizing pages, edit warring or trolling along with many other reasons.
|
{{Banned user}}
This user has been banned for an unspecified reason, such as spamming, vandalism, copyright violations, sockpuppetry, edit warring, trolling or harassment, and/or violating the Valve Developer Community's Terms of Use along with other misbehavior. |
{{Stub}} marks pages that are very small. See Help:Stubs for info on using.
|
{{Stub}} |
{{Translate}} marks pages where translation is needed and adds the page to a category.
|
{{Translate}} This page needs to be translated. This page either contains information that is only partially or incorrectly translated, or there isn't a translation yet. If this page cannot be translated for some reason, or is left untranslated for an extended period of time after this notice is posted, the page should be requested to be deleted. Also, please make sure the article tries to comply with the alternate languages guide. |
{{Update}} marks outdated pages.
|
{{Update}} This article or section needs to be updated to include current information regarding the subject. Remember to check for any notes left by the tagger at this article's talk page. |
{{Wip}} marks pages that are in the middle of major edits. The adder requests that other users do not edit in the meantime.
|
{{Wip}} This Help page is actively undergoing a major edit. As a courtesy, please do not edit this Help while this message is displayed. If this page has not been edited for at least several hours to a few days, please remove this template. This message is intended to help reduce edit conflicts; please remove it between editing sessions to allow others to edit the page. The person who added this notice will be listed in its edit history should you wish to contact them.
|
{{Draft}} marks pages that are currently being worked on.
|
{{Draft}} This is a draft help page. It is a work in progress open to editing by anyone. Remember to check for any notes left by the tagger at this article's talk page.
|
{{Rewrite}} marks pages that are being rewritten, usually with a wip version on another page.
|
{{Rewrite This help is currently being rewritten. The rewrite can be found at Help:Templates. You can discuss the changes here. |
Miscellaneous Templates
These templates have the purpose of helping the editor.
Description | Wikitext and Result |
---|---|
Template:= is a template that only returns an equal sign. The character is sometimes needed because multiple wiki features make use of it. Especially, the equals sign is a special character in template calls, so if an equals sign should be passed as a parameter value, then {{=}} is needed for "escaping". For the same purpose, there is also Template:! for a pipe, Template:((( for curly brackets and many more, see Category:Templates for within templates.
|
{{=}} = |
{{Note Note:If x = 0, you lose.
| |
Template:Clr clears the vertical space to the left and right of floating tables, floating images etc. To clear only one side, use {{Clr or {{Clr . This is commonly used before headlines to push them down so that they don't appear next to an image. In the example on the right, one could also use {{Clr for the same effect.
|
[[File:Skull and crossbones.png|50px|left]]
This text is next to the image.{{clr}}This text is below the image. This text is next to the image.This text is below the image. |
Template:Ent is a really small template for linking entity pages. | {{Ent info_target
|
Template:Expand allows you to hide stuff inside a box that can be shrunk down so that it doesn't make pages as long. | Todo: example
|
Template:Param displays the values like parameters in the way that they are used in templates. Useful for template documentations. | {{Param {{{color|#FFF}}} |
Template:Shortcut displays a small box noting (abbreviated) redirects to a page. | {{Shortcut |
Template:T stands for Template. It creates a link to a template surrounded by {{ and }} . It is also possible to specify parameters using the {{P}} template in the second parameter of the {{T}} template. To disable a link, specify the template name at the beginning of the second parameter, leaving the first parameter empty.
|
{{T {{Delete {{T {{Delete
|
Template:Toc-right shifts the table of contents over to the right side of a page. | For an example, see Half-Life 2 map reference. |
Template:Unsigned is for talk pages. It should be added at the ends of unsigned comments. | {{Unsigned —Unsigned comment added by JeffLane (talk • contribs) Always sign your posts with four tildes ( ~~~~ )
|
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.
__NOINDEX__
Tells webcrawlers not to index pages, so they don't appear in search results. Also adds the page to Category:Noindexed pages. It has no effect on articles (in practice, because there are almost no patrolled edits on this wiki), but always effects other namespaces (such as templates, user pages, talk pages, etc.)
{{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.
- New Help Desk – Questions? Ask here.