Editing Help:Templates

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
{{navbar help}}
+
''MediaWiki Help article: [https://www.mediawiki.org/wiki/Help:Templates Help:Templates]''
 +
==Using Templates==
 +
===Summary===
 +
Templates are to improve wiki efficiency by allowing editors to write less on pages by transcluding these preset templates. For example, if you type <code><nowiki>{{Stub}}</nowiki></code> this shows on the page:
  
{{Ambox
+
{{rwbox|nocat=true|type=notice|text=''This is a '''[[:Category:Page Stub|Stub]]''' page. You can help {{SITENAME}} by '''[{{fullurl:{{#titleparts:{{FULLPAGENAME}}|1}}|action=edit}} expanding it]'''.}}
|type=For a list of all the templates on the RimWorld Wiki, see [https://rimworldwiki.com/wiki/Special:AllPages?from=&to=&namespace=10 this list].
 
|border=yellow
 
|style=font-size:80%
 
}}
 
<br/>
 
  
At their most basic, '''templates''' are basically just wiki pages whose content may be pulled into other pages. In other words, all the content you see when viewing a page may not actually be in the page source. Some or even all of it may be in templates.
+
In a nutshell, templates save up space and create consistency.
  
Two very common types of templates are shown here as examples:
+
===Parameters===
* To the right, there is an example of an "infobox" template. Nearly every wiki provides at least one of these.
+
Some templates take parameters. For instance, [[Template:Asof]] takes a value from A1 to the current alpha version.<br />
* Below, there is an example of a navigation template called a "navbox" - typically used at the bottom of pages.
+
'''Example:'''
{{Navbar example}}
+
<pre>{{Asof|A16}} luciferium can heal scars.</pre>
<!-- Infobox should be higher on the page, but the navbar mucks it up -->
+
'''Result:'''<br />
{{Infobox example
+
{{Asof|A16}} luciferium can heal scars.
| name    = Phoebe
 
| image    = Phoebe friendly.png
 
| race    = Human
 
| location = RimWorld
 
| source  = Tynan's inner circle
 
| reward  = Happiness
 
| related  = Calming bliss
 
| ID      = Phoebe_ID
 
}}
 
  
Speaking generally, a template is any wiki page whose content is designed to be [[wikipedia:Wikipedia:Transclusion|transcluded]] (embedded) inside other pages. Templates follow a convention that the name is prefixed with <code>Template:</code>, assigning it to that [[wikipedia:Wikipedia:Namespace|namespace]].
+
Templates like [[Template:Rewrite]] take special parameters. The way to use them is to type the pipe (|) symbol, followed by the parameter name, and then the value.<br />
 +
'''Example:'''
 +
<pre>{{Impressive
 +
|title=Demo
 +
}}</pre>
 +
'''Result:'''
 +
{{rwbox|nocat=true|type=notice|text=''This is an '''[[:Category:Impressive|Impressive]]''' page, and is giving a <span style=color:green>+3</span> positive [[thoughts#Rec Room|thought]] to all [[colonist|colonists]] viewing this page. Please consider leaving the page as is, or decorating this page with [[sculptures]]. The impressiveness of this page at the moment is <b style="color:green">{{#expr:({{#time:s}}/4+95)round 0}}</b>. It has also been deemed the title: '''Demo'''. }}
  
== Templates in the page source ==
+
==Creating a template==
When editing wiki pages, it is likely you might encounter something like this:
+
===Basics===
 
<nowiki>{{navbar example}}</nowiki>
 
  
Or perhaps something more complex like this:
+
===Parameters===
+
[[Category:Help pages]]
<nowiki>{{Infobox example
 
| name    = Phoebe
 
| image    = Phoebe friendly.png
 
| race    = Human
 
| location = RimWorld
 
| source  = Tynan's inner circle
 
| reward  = Happiness
 
| related  = Calming bliss
 
| ID      = Phoebe_ID
 
}}
 
</nowiki>
 
 
 
These are examples of templates being used on these wiki pages. The first is using <nowiki>[[Template:navbar example]]</nowiki>, the second is using <nowiki>[[Template:Infobox example]]</nowiki>. The double curly brackets, <code>{{</code> and <code>}}</code> usually mean that a template is being used there, but unfortunately, double curly brackets also have other uses in wikitext, which can cause some confusion.
 
 
 
=== How to tell if it's a template ===
 
Let's look at our examples above again.
 
 
 
<nowiki>{{Infobox example
 
| name    = Phoebe
 
| image    = Phoebe friendly.png
 
| race    = Human
 
| location = RimWorld
 
| source  = Tynan's inner circle
 
| reward  = Happiness
 
| related  = Calming bliss
 
| ID      = Phoebe_ID
 
}}
 
</nowiki>
 
 
 
In this case, we have a definite clue because the first thing after the name other than just space is a pipe character: (<code>|</code>). This is definitely a template. If it were a colon instead, (<code>:</code>), then it would not be a template, but some kind of [[Wikipedia:Help:Magic words|magic word]].
 
 
 
<nowiki>{{navbar example}}</nowiki>
 
 
 
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 that it is a template is that it ''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 "{{int:savearticle}}" and other buttons. If it's listed there, it's definitely a template.
 
* If it isn't a documented [[Wikipedia:Help:Magic words|magic word]], it's almost certainly a template.
 
 
 
== Basic transclusion ==
 
Transclusion is by far the most common way to use templates.
 
 
 
* <code><nowiki>{{Name}}</nowiki></code> — as described above, this link will be dynamically replaced by the current content of <nowiki>[[Template:Name]]</nowiki> at the time the page with the template link is loaded. The page's source will be unchanged.
 
 
 
In fact, an ordinary wiki page can also be used as a template, simply by specifying the namespace in which it resides, so:
 
* <code><nowiki>{{Template:Pagename}}</nowiki></code> includes <code><nowiki>[[Template:Pagename]]</nowiki></code>
 
* <code><nowiki>{{Foo:Pagename}}</nowiki></code> includes <code><nowiki>[[Foo:Pagename]]</nowiki></code>
 
* <code><nowiki>{{:Pagename}}</nowiki></code> includes <code><nowiki>[[Pagename]]</nowiki></code>
 
** <code><nowiki>{{SUBST::Pagename}}</nowiki></code> replaces itself with the contents of <code><nowiki>[[Pagename]]</nowiki></code>
 
 
 
If no such namespace exists, the full title is assumed to be a template:
 
 
 
* <code><nowiki>{{Foo:Bar}}</nowiki></code> includes <code><nowiki>[[Template:Foo:Bar]]</nowiki></code>
 
 
 
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 [[#Alternate ways to use templates|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. If it's not documented, consider writing your own template documentation.
 
 
 
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. However, templates can be very complex and may use advanced wiki features or specific extensions, like any other wiki page. If all else fails, never hesitate to ask for assistance from the [[RimWorld Wiki:Community portal|staff]] or wiki community.
 
 
 
== Alternate ways to use templates ==
 
In addition to standard transclusion, templates can be used in other pages in these ways:
 
 
 
* <code><nowiki>{{subst:Name}}</nowiki></code> — when this template link is used, it will be replaced once and for all with the content of <nowiki>[[Template:Name]]</nowiki> as of the time the page with the link is '''saved'''; a copy of the contents of <nowiki>[[Template:Name]]</nowiki> 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. Changes to the source template page will ''not'' be propagated to the page with the template link.
 
* <code><nowiki>{{safesubst:Name}}</nowiki></code> — 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 <nowiki>{{Firstname}}</nowiki> within <nowiki>[[Template:Name]]</nowiki>. If you use <nowiki>{{subst:Name}}</nowiki>, the <nowiki>{{Firstname}}</nowiki> will be saved on the page. If you try to change it to <nowiki>{{subst:Firstname}}</nowiki> inside <nowiki>[[Template:Name]]</nowiki>, then it'd be substituted inside the template. safesubst: doesn't substitute until the template containing it is used with <code>subst:</code>.
 
* <code><nowiki>{{msgnw:Name}}</nowiki></code> includes the template in a form that displays it as raw wiki syntax (the way <code><nowiki>&lt;nowiki&gt;</nowiki></code> does) when the page containing it is fetched.
 
 
 
== See also ==
 
* [[Wikipedia:Help:A quick guide to templates|Wikipedia]]'s quick guide to templates
 
 
 
[[Category:Help]]
 

Please note that all contributions to RimWorld Wiki are considered to be released under the CC BY-SA 3.0 (see RimWorld Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)