Help:Template
This page is not a witty article nor a guideline. Rather it is a information page so expect little humour. |
Here you will find our Official Guide to Templating. It is intentionally simplified, since templating can get really complicated really fast. You may want to see Wikipedia's help page on templates for more detailed info.
What are templates?[edit source]
Templates are pages (usually snippets of wikitext and markup) which are transcluded or substituted onto other pages. They have many different functions, but the most obvious use of templates is to make all those obnoxious message boxes and infoboxes you see in articles.
Where are they?[edit source]
Templates can be found in the template namespace. For example, the
For. voting template can be found in Template:For. You may also see links to template like this: {{for}}.
A listing of all categorized templates can be found in Category:Templates.
Realistically, to find the kind of templates you might want to use when writing an article, your best bet is to look at the type of article you want to write (i.e. is it about a city, or a country, or a celebrity?), find a corresponding article similar to your idea (preferably a featured one), and check the source code for the kinds of templates those articles use. For example, China uses Template:Infobox country and Jeffrey Epstein uses Template:Infobox person.
What are they for?[edit source]
Templates are meant for content which would be annoying to continuously copy and paste among multiple pages. Let's look at an example of transcluding a template.
Here is the wikitext for Template:Example, a very simple grey text box with some example text.
<div style="width:400px; margin:10px auto; padding:10px; background:#ddd; border:1px solid #aaa; font-weight:bold; text-align:center"> Example text. </div>
This markup will produce the text box you see below.
Example text.
Transclusion[edit source]
Now, this is where templates can come in handy: rather than having to copy-and-paste all that weird looking text, you can simply transclude a template which already has that text with a template call. First, you must don your favorite milkmaid outfit and find a verdant hill or knoll fit for yodeling. Then, you add this code to your page:
{{example}}
See? Much simpler. The complicated looking wikitext found at Template:Example will now be added to whatever page you want.
Substitution[edit source]
There are a few cases where you might need to substitute a template instead, like in a signature. This will directly spit out all the contents of the template onto the page itself, leaving no trace of the template. You can substitute a template like so:
{{subst:example}}
Now we can talk about parameters.
What are parameters?[edit source]
In templates, parameters are inputs we can use to customize the look or behavior of templates. Let's look at the wikitext for Template:Example now. You may notice something different.
<div style="width:400px; margin:10px auto; padding:10px; background:{{{2|{{{color|#ddd}}}}}}; border:1px solid #aaa; font-weight:bold; text-align:center">
{{{1|Example text.}}}
</div>
The {{{1|Example text.}}} is a positional or unnamed parameter. The text you see past that | symbol is called a default value. It is the default stuff that the template will spit out if you don't specify the parameter yourself. Here's how we can customize a positional parameter when we transclude a template.
{{example|Got any beans?}}
This markup will produce the template you see below:
Got any beans?
Notice how the number in the {{{1}}} parameter corresponds with the position of the parameter. Getting confused?
Now let's look at this scary looking parameter: {{{2|{{{color|#ddd}}}}}} Whoah nelly! It looks scary, but it's really just two separate parameters smushed together which do the same thing.
- The
{{{2}}}part is the second positional parameter. - The
{{{color}}}part is a named parameter which also acts as a fallback parameter. This means that if you don't call the second positional parameter, it will fallback to the{{{color}}}parameter, but only if you provided it. - The
#dddis the default value, meaning if you don't provide{{{2}}}or{{{color}}}, it will default to that. Since the parameter is inside a CSS declaration inside thedivelement's style attribute, this whole parameter mishmash controls the color of the box.
I hope that all made sense to you. Now we can combine what we've learned together.
{{example|Got any beans?|orange}}
The markup will produce the template you see below:
Got any beans?
Notice how the value orange is in the second position?
{{example|color=orange|Got any beans?}}
This markup will also produce the template you see below:
Got any beans?
Despite color=orange looking like it's in the first position, the parser will look at unnamed parameters first when determining the value of a positional parameter, and will ignore the position of a named parameter, unless you call the positional parameters directly via 1=, in which case... did you just fall asleep? This stuff is important!
What are modules?[edit source]
Modules are, as you guessed, modules of lua code found in the Modules namespace. They are usually not called directly, but instead invoked either in a wrapper template, or as one part of a template, or even another module. For example, Module:YouTube is invoked inside Template:YouTube like this:
{{#invoke:YouTube|main}}
You can then use the YouTube template like a normal template, with the module doing the hidden work of making the template work, and you can transclude it normally like so:
{{YouTube}}
Advanced tips[edit source]
Here are some tips for more advanced users. Remember, your templating journey is never over, and the lessons you learn on Uncyclopedia can also be used to enrich your experience on lesser, more provincial wikis.
- The edit page of an article will include all the templates the page uses, in a list below the edit box.
- Read the documentation! Unless no one bothered to write it, in which case, stare at the template's source code until the true nature of the template is revealed to you, as if in a dream. You will find yourself writing the documentation, compelled by a force greater than human reckoning.
- For template editors, the "Inspect Element" tool of your browser will become your worst friend, and your best enemy.
- If an unnamed parameter (like
{{{1}}}) contains an equal sign (=), you will have to call it directly, like1=.This is a fact that every Wikipedian knows, but will never tell you. They enjoy their rarified, arcane knowledge of wiki editing, and the depths of submission you must stoop to gain their knowledge. We on the other hand, give knowledge freely!