Help:Templates: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(aaaaa)
(subs)
Line 130: Line 130:


===confirm===
===confirm===
[[Template:Confirm]] marks something that needs to be confirmed.
[[Template:Confirm]] marks something that needs to be confirmed. It's green color is meant to stand out.
<pre>{{confirm|Always goes to the left.}}</pre>
<pre>{{confirm|Always goes to the left.}}</pre>
Result: {{#if: Always goes to the left. | <div style="margin:0.4em 1em 0.5em;"><strong style="color:#8BC53F;display:table-cell;text-align:right;white-space:nowrap;padding-right:0.3em;">[[File:Confirm.png|link=|alt=]] Confirm:</strong><span style="display:table-cell;">Always goes to the left.</span></div> | <sup style="color:#8BC53F;">&#91;''confirm''&#93;</sup> }}[[Category:TODO]][[Category:CONFIRM]]
Result: {{#if: Always goes to the left. | <div style="margin:0.4em 1em 0.5em;"><strong style="color:#8BC53F;display:table-cell;text-align:right;white-space:nowrap;padding-right:0.3em;">[[File:Confirm.png|link=|alt=]] Confirm:</strong><span style="display:table-cell;">Always goes to the left.</span></div> | <sup style="color:#8BC53F;">&#91;''confirm''&#93;</sup> }}
<pre>Always goes to the left.{{confirm}}</pre>
<pre>Always goes to the left.{{confirm}}</pre>
Result: Always goes to the left.{{#if:  | <div style="margin:0.4em 1em 0.5em;"><strong style="color:#8BC53F;display:table-cell;text-align:right;white-space:nowrap;padding-right:0.3em;">[[File:Confirm.png|link=|alt=]] Confirm:</strong><span style="display:table-cell;">{{{1}}}</span></div> | <sup style="color:#8BC53F;">&#91;''confirm''&#93;</sup> }}[[Category:TODO]][[Category:CONFIRM]]
Result: Always goes to the left.{{#if:  | <div style="margin:0.4em 1em 0.5em;"><strong style="color:#8BC53F;display:table-cell;text-align:right;white-space:nowrap;padding-right:0.3em;">[[File:Confirm.png|link=|alt=]] Confirm:</strong><span style="display:table-cell;">{{{1}}}</span></div> | <sup style="color:#8BC53F;">&#91;''confirm''&#93;</sup> }}


===delete===
===delete===
Line 212: Line 212:
|image = None
|image = None
}}
}}
===tip===
[[Template:Tip]] marks text as a tip to readers.
<pre>{{tip|This is a much less tricky process when using the vertex edit tool as well.}}</pre>
Result: {{tip|This is a much less tricky process when using the vertex edit tool as well.}}
===todo===
[[Template:Todo]] marks things that need to be done. It's green color is meant to stand out.
<pre>{{todo|Find where this is in the game files.}}</pre>
Result: <strong style="color:#8BC53F;white-space:nowrap;">To do{{#if: Find where this is in the game files. | &#58;&nbsp; }}</strong>Find where this is in the game files.[[Category:TODO]]
===update===
[[Template:Update]] marks outdated pages.
<pre>{{update}}</pre>
Result:
{{messagebox
|text = This article needs to be '''updated''' to include current information regarding the subject.
|image = [[File:broom_icon.png|40px]]
}}
[[Category:Cleanup]]
===warning===
[[Template:Warning]] marks things that readers should take caution of when doing something.
<pre>{{warning|This tool has been known to corrupt files. Try an alternative listed below.}}</pre>
Result: {{warning|This tool has been known to corrupt files. Try an alternative listed below.}}
===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.
<pre>{{WIP|~~~}}</pre>
{{messagebox
|text =
'''This article is actively undergoing a [[Wikipedia:Wikipedia:Edit_lock|major edit]].'''<br /> As a courtesy, please do not edit this article 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 [[Wikipedia:Help:Edit_conflict|edit conflicts]]; please remove it between editing sessions to allow others to edit the page.
{{ #if: [[User:Pinsplash|Pinsplash]] ([[User talk:Pinsplash|talk]]) | The user who added this notice, should you wish to contact them, is: [[User:Pinsplash|Pinsplash]] ([[User talk:Pinsplash|talk]]) | The person who added this notice will be listed in its [{{SERVER}}{{localurl:{{NAMESPACE}}:{{PAGENAME}}|action=history}} edit history] should you wish to contact them. }}
|image = [[File:Under construction.png|55px]]
|bdcolor = #FF7700
}}
[[Category:Articles actively undergoing a major edit]]


==See Also==
==See Also==
*[[Wikipedia:Help:Template]] - a very helpful resource for template programming.
*[[Wikipedia:Help:Template]] - a very helpful resource for template programming.
*[[New Help Desk]] - Questions? Ask here.
*[[New Help Desk]] - Questions? Ask here.

Revision as of 12:35, 23 July 2018

Help:Editing

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 |.

Note.pngNote:Any page can be transcluded by another one actually. Below is a transclusion of the Main Page:

English (en)Deutsch (de)Esperanto (eo)Español (es)Français (fr)Suomi (fi)Hrvatski (hr)Italiano (it)日本語 (ja)한국어 (ko)Nederlands (nl)Polski (pl)Português do Brasil (pt-br)Русский (ru)Slovenčina (sk)Svenska (sv)Türkçe (tr)Українська (uk)Tiếng Việt (vi)中文 (zh)中文(臺灣) (zh-tw)
Welcome to the
Valve Developer Community
13,094 articles documenting the development process.

Whether you're building a commercial project or a modification for Half-Life® 2, you'll want to sign up as a Valve developer today. It's free to join and is open to anyone working with the Source engine and its software development kit.

Examples

Here's a template where we don't define any parameters, you just drop it right in.

{{restart}}

Result: Requires restart to take effect.

If you visit this template's page, you'll see that its just those five words.


The ent template is a template that can accept up to two unnamed parameters.

{{ent|sv_cheats|1}}

Result: sv_cheats 1

Unnamed parameters must be defined in a specific order.


KV is one of the most common templates used. It accepts an optional named parameter (since).

{{KV|Script think function (thinkfunction)|string|Name of a function in this entity's script which will be called automatically every 100 milliseconds (ten times a second) for the duration of the script. It can be used to create timers or to simulate autonomous behavior. The return value (if present) will set the time until the next call.|since=l4d2}}

Result:

Script think function (thinkfunction) ([todo internal name (i)]) <string> (in all games since Left 4 Dead 2)
Name of a function in this entity's script which will be called automatically every 100 milliseconds (ten times a second) for the duration of the script. It can be used to create timers or to simulate autonomous behavior. The return value (if present) will set the time until the next call.

Without the |since=l4d2 at the end, the Template:L4d2 add message would not have displayed. Named parameters can be defined in any order.

Templates can also use templates (nesting). In the KV template above, the |since=l4d2 part adds {{l4d2 add}} into the page, which is the Template:L4d2 add message.

Making templates

Making a template like Template:Restart is rather easy - just type the text you want, and save it. What about ones with parameters?

Tip.pngTip:When making templates, you may want to space out your code to make it easier to read, but watch out for unintentional whitespace.

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:

Tip.pngTip:Do not carve without vertex editing afterward.

If you want to add more than one unnamed parameter, simply change the number. Here's the (condensed) code for Template:Distinguish:

:''Not to be confused with [[:{{{1}}}]]{{#if:{{{2|}}} |{{#if:{{{3|}}} |, [[:{{{2}}}]]| or [[:{{{2}}}]].}}|.}}{{#if:{{{3|}}} |{{#if:{{{4|}}} |, [[:{{{3}}}]]|, or [[:{{{3}}}]].}}}}{{#if:{{{4|}}} |, or [[:{{{4}}}]].}}''

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}}}.

All the user has to do when transcluding is this:

{{distinguish|Combine|Civil Protection|Overwatch}}

Result:

Not to be confused with Combine, Civil Protection or 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:

{{IO|SetString|Updates the string.|param=string}}

Result:

SetString <string>
Updates the string.


Without named parameter:

{{IO|SetString|Updates the string.}}

Result:

SetString
Updates the string.

Parser Functions

#if: checks if a string or parameter has anything inside it.

{{#if: {{{target|}}} | Target aqcuired | Sleep mode activated... }}

Result: Sleep mode activated... (The parameter {{{target|}}} returns null because you (probably) are not viewing this page through a transclusion, so it's never had a chance to be defined.)

{{#if: Something is there! | Target aqcuired | Sleep mode activated... }}

Result: Target aqcuired


#ifeq: checks for equality between two strings. It can be used with parameters as well.

{{#ifeq: {{{target|}}} | friend | Friend... | Go away! }}

Result: Go away!

{{#ifeq: friend | friend | Friend... | Go away! }}

Result: Friend...


#expr: solves math problems.

{{#expr: 2 + 2}}

Result: 4

See m:Help:Calculation for all it's abilities.


#ifexpr: tells if a math expression is correct.

{{#ifexpr: 6 + 3 = 9 | Right | Wrong }}

Result: Right

{{#ifexpr: 6 + 3 = 23 | Right | Wrong }}

Result: Wrong

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 tempalte's page.

includeonly wikitext inside this will not appear on the template page. It has no effect on the destination page however.

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.

Useful templates

per-game templates

All games have templates that show their associated icon. (e.g. Half-Life 2) See Category:Game icons for the full list.

Most games also have templates to quickly note what game added a core engine feature. (e.g. Template:CSGO add) See Category:Notice templates for all available.

bug

Template:Bug notifies readers of a bug.

{{bug|The amount is double what it should be. Be careful!}}

Result:

Icon-Bug.pngBug:The amount is double what it should be. Be careful!  [todo tested in ?]

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:

confirm

Template:Confirm marks something that needs to be confirmed. It's green color is meant to stand out.

{{confirm|Always goes to the left.}}

Result:

Confirm:Always goes to the left.
Always goes to the left.{{confirm}}

Result: Always goes to the left.[confirm]

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.

{{delete|This is not a real thing.}}

Result:

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:

Tip.pngIdea:Reward players for being clever and creative, instead of forcing things to be only one way.

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 done.

{{merge|HDR}}

Result:

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:

morescreenshots

Template:Morescreenshots marks pages that should have more images on them.

{{morescreenshots}}

Result:

note

Template:Note is for making notes stand out more.

{{note|This will spawn at the map origin if you do not specify the position.}}

Result:

Note.pngNote:This will spawn at the map origin if you do not specify the position.

obsolete

Template:Obsolete marks things that should no longer be used.

{{obsolete}}

Result:

spammer

Template:Spammer marks users that should be banned for spamming.

Icon-Bug.pngBug:This template's formatting may look weird sometimes. It's intended to be the only thing on a page.  [todo tested in ?]
{{spammer}}

Result:

Spammer.jpg
Note.pngNote:This user is a spammer, vandal or other problem poster and should be considered for a ban

stub

Template:Stub marks pages that are very small. It's okay if a page simply is small, though!

{{stub}}

Result:

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:

Tip.pngTip:This is a much less tricky process when using the vertex edit tool as well.

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.

update

Template:Update marks outdated pages.

{{update}}

Result:


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:

Warning.pngWarning:This tool has been known to corrupt files. Try an alternative listed below.

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|~~~}}


See Also