Gamepedia帮助Wiki
"Hydra guy"
Curse hydra
Details
Race
Plushie
Location(s)
Curse Headquarters
Source
Encredechine
Related
Fun

从最基本的角度来说,模板只是一个Wiki页面,其内容可能会被嵌入其他页面。换句话说,您在查看页面时看到的内容可能不在页面源中,它的某些部分可能在模板中。

这里以两种非常常见的模板类型为例:

  • To the right, there is an example of an "infobox" template. Nearly every wiki provides at least one of these.
  • Below, there is an example of a navigation template typically used at the bottom of pages.
  • Templates can be very simple. This text here is being lightened by a template called {{Ghost}}.

Speaking generally, a template is any wiki page whose content is designed to be transcluded (embedded) inside other pages. Templates follow a convention that the name is prefixed with "Template:", assigning it to that namespace.

模板源代码[ | ]

编辑Wiki页面时,您可能会遇到以下情况:

{{Example}}

或更复杂一些,像这样:

{{Ghost|Making text lighter.}}

Which gives you: Making text lighter.

Or perhaps something even more complex like this (Note that this is the code used to transclude the infobox template at the top of the page):

{{Infobox
| name = Hydra guy
| image = Curse hydra.png
| race = Plushie
| location = Curse Headquarters
| source = [[User:Encredechine{{!}}Encredechine]]
| reward = 
| related = Fun
| ID = 
}}

These are examples of templates being used on these wiki pages. The first is using [[Template:Example]], the second is using [[Template:Ghost]], and the third is using [[Template:Infobox]]. The double curly brackets, {{ and }} usually mean that a template is being used there, but unfortunately, double curly brackets also have other uses in wikicode, which can cause some confusion.

How to tell if it's a template[ | ]

Let's look at our examples above again.

{{Infobox
| name = Hydra guy
| image = Curse hydra.png
| race = Plushie
| location = Curse Headquarters
| source = [[User:Encredechine{{!}}Encredechine]]
| reward = 
| related = Fun
| ID = 
}}

In this case, we have a definite clue because the first thing after the name other than just space is a pipe character: (|). This is definitely a template. If it were a colon instead, (:), then it would not be a template, but some kind of magic word.

{{Example}}

Unfortunately, this one doesn't offer any definite clues right off the bat. If you aren't sure, there are a few ways to make a pretty good guess:

  • One clue is that it is a template is that isn't in all capital letters. Virtually all magic words that don't require a colon are typed in all caps.
  • To be sure, when editing a page, you should see "Templates used on this page" at the bottom of the screen under the "Save Page" and other buttons. If it's listed there, it's definitely a template.
  • If it isn't a documented magic word, it's almost certainly a template.

Basic transclusion[ | ]

Transclusion is by far the most common way to use templates.

  • {{Name}} — as described above, this link will be dynamically replaced by the current content of [[Template:Name]] at the time the page with the template link is loaded. The link will remain unchanged in the page's source.

In fact, an ordinary wiki page can also be used as a template, simply by specifying the namespace it resides in, so:

  • {{Template:Pagename}} includes [[Template:Pagename]]
  • {{Foo:Pagename}} includes [[Foo:Pagename]]
  • {{:Pagename}} includes [[Pagename]]
    • {{subst::Pagename}} replaces itself with the contents of [[Pagename]]

If no such namespace exists, the full title is assumed to be a template:

  • {{Foo:Bar}} includes [[Template:Foo:Bar]]

There are other ways of using templates, but these are useful only in special situations. Most editors will never have any use for these special functions, so they are explained only at the bottom of this page.

Template documentation[ | ]

Many template authors provide documentation for how to use specific templates. This can usually be found on the template page itself. If you are editing a page using a particular template, one way you can usually get to the template page quickly is by using the "Templates used on this page" section at the bottom of the edit page.

Unfortunately, many templates are not documented. In this case, you can try looking for examples of the template being used on other pages. From the template page, try clicking "What links here" in the "Tools" menu in the sidebar to find other pages where the template is used.

It can help to understand how to write templates. Once you do, you may be able to figure out a template simply by opening it for editing and looking at its source, but templates can be very complex and may use advanced wiki features or specific extensions, like any other wiki page. If all else fails, it is probably best to simply ask for assistance from the wiki community.

Transclusion and alternate ways to use templates[ | ]

Templates can be used in other pages in these ways:

  • {{Name}} — as described above, this link will be dynamically replaced by the current content of [[Template:Name]] at the time the page with the template link is loaded. The link will remain unchanged in the page's source.
  • {{subst:Name}} — when this template link is used, it will be replaced once and for all with the content of [[Template:Name]] as of the time the page with the link is saved: a copy of the contents of [[Template:Name]] will be substituted for the template link. The contents are then a part of the including page, and can be edited normally, separately from the original. Note: changes to the source template page will not be propagated to the page with the template link.
  • {{safesubst:Name}} — this is for special cases where a template may be designed to work both through transclusion and substitution. For example, say you used a template {{Firstname}} within [[Template:Name]]. If you use {{subst:Name}}, the {{Firstname}} will be saved on the page. If you try to change it to {{subst:Firstname}} inside [[Template:Name]], then it'd be substituted inside the template. safesubst: doesn't substitute until the template containing it is used with subst:.
  • {{msgnw:Name}} includes the template in a form that displays it as raw wiki syntax (the way <nowiki> does) when the page containing it is fetched.

In fact, an ordinary wiki page can also be used as a template, simply by specifying the namespace it resides in, so:

  • {{Template:Pagename}} includes [[Template:Pagename]]
  • {{Foo:Pagename}} includes [[Foo:Pagename]]
  • {{:Pagename}} includes [[Pagename]]
    • {{subst::Pagename}} replaces itself with the contents of [[Pagename]]

If no such namespace exists, the full title is assumed to be a template:

  • {{Foo:Bar}} includes [[Template:Foo:Bar]]