Help:Templates

For information on the templates standardly used on the YPPedia, take a look at the style guide. Most of the more complex templates should have directions for use on their talk pages.

What are templates, and why are they used?
On a basic level, templates are a way to arrange things. On a more complex level, they can be used to program things. Both sorts of templates will be looked at later on, but it's useful to remember that the main aim of them is to save time and effort.

A basic template will take the following form:

At first, it looks quite scary, but if it's broken into bits, it all seems to be quite logical:
 * The 🇦🇩 parts, often called curly brackets, just indicate where the template starts and ends.
 * The Name part is the name of the template. By typing that part in, it will call the template into use. Each template has a name, and of course, all templates do very different things from each other.
 * The vertical bar, or pipe, | separates the templates into the name and the parameters.
 * The 1=parameter bits are indeed parameters. These simply tell the template what to fill in and where. Often, the 1= bits are omitted, as they're not always needed. However, it's worthwhile knowing that they exist, especially when making templates.

Now let us look at a basic form of template.

No parameters
Many pages are incomplete. As such, they are marked as stubs, or short articles. They can easily be designated with the stub template. The stub template can be found at the page Template:Stub. The template will always be found at Template:Name where Name is the name of a template.

The template can be called by typing as such:

(It is possible to type without it being substituted, by use of things called nowiki tags. Normally, anything inside curly brackets get converted into a template, but by typing   , it won't substitute it.)

On the Template:Stub page, it contains the following code:

''Arr! This article be a stub. Ye can help YPPedia by [ expanding it].''

It looks pretty ugly, especially if you don't understand HTML. It's much easier to type than all that, especially for a new person. What's more,it's simple to remember.

There's also a third benefit - if the template was changed, it would automatically update on all pages, rather than having to be manually retyped on all pages. The stub article is used many hundreds of times - imagine how much of a Herculean task that would be to update!

Now, an example of a template that uses a parameter:

One parameter
Templates with more parameters are more interesting.

Take, for example, the template Template:Test font. Its contents are the following:

The noinclude and category bits are of no interest here.

What this template does is to take a parameter and turn it green.

Using the template is simple: typing or  gives.

Instead of having to write verbose HTML code for green font to emphasise, say, a correct answer, that template can be used. Again, if needed subsequently to change the color of everything to a different shade of green, it could be done with just one edit rather than one for each instance.

Two parameters
Templates with multiple parameters allow for greater variety, but also a greater scope for confusion.

Quite often, templates of the sort like Template:Test writing come about:

  

(The functional part of this template is in bold)

This template allows the editor to write a block of text in a certain color.

To call this template, the following syntax would be used:

This would tell the browser to:
 * Use the Test writing template,
 * Use  cyan colored text 
 * Use the cyan colored text on the word hello.

This would result in the following:

Equals signs, words and numbers - oh my!
In the template with just one parameter, the template contained the text. This told the browser to replace with whatever was assigned as the first parameter.

In the two parameter example, numbers won't work:

gives the funny looking:

More detail on this can be found at the Wikipedia help page, at the bottom.

In short:

It is important when calling templates to use the correct words, otherwise things may not always work out.

In fact, there is a way to allow multiple inputs for a certain template. This requires the use of parameter defaults that make things look much more complex. For the interested reader, the following code would allow both a text= color= and a 1= 2= approach to work:



Repeated uses of values
Say, for example, that a certain word had to be printed out 10 times in a row. A template such as Template:X10 can handle this.

To use, simply write the following:

where text is the text needed to be repeated 10 times.

For example:

yields:

Note that the template cannot add spaces in. A separate template with the 's with spaces in between would have to be constructed. Alternatively:

yields

although this results in a space at the end of the final hello.

Further examples:

yields

The parameter input can even take other templates:

yields

This is an easy way to repeat something 100 times without ever having to make a x100 template.

Using clever tricks to save effort and time are the keys to being an excellent template user.

Aside: It would theoretically be possible to create a way to construct a template Xn for any n (where n is a natural number), using just the templates for the prime numbers. Exactly how to do that is again left as an exercise for the interested reader (and the mathematicians!). However, there is limited use for such a thing.

=Substitution=

Sometimes, there is the need to substitute some text into an article, for example with the RfA page. Doing this is quite simple; all that is needed to be done is to add subst: to the beginning of the template, as such:

gives: Hello, but will actually show:



instead of in the edit page section.

It is worth noting that substitution is irreversible (except for reverting a page); that is, the substitution occurs when a page is submitted, and once submitted, it leaves no characteristic trace of which template it actually came from. Substitution is rare, since it can no longer be controlled by an edit in the template page. Nevertheless, it is useful to know.

=See Also=
 * Help:Making templates
 * Help:Fixing templates

=External Links=
 * Wikipedia's Quick Guide to Templates