User:Soni/Templates adoption

Templates
Hello, I'm TheOriginalSoni and I'll be your teacher for this lesson on templates.

Let's just start with the basics now - Any page that has a  before it's name is in the Template namespace, and is a template. They function to help make things a lot simpler when you are editing any page. A template is simply a different page whose contents can be seen from another page by calling it.

Lets say you have a page Calling page where you want some text to appear. But you do not want to deal with the huge mess of text in the editing window, and would want it replaced by just a few characters which would do the same work. That is when you use a template.

First, we make a page (Lets say Template:Template page) where you have whatever information you wanted to view on Calling page. Since it is in the Template namespace, we can use it as a template, and call it from Calling page now.

To call the template, you use the following code on Calling page -. When you do that, whatever is in Template:Template page gets automatically displayed in place of  every time you open Calling page. Now if you want to change some text, you have to change Template name, and the change will be automatically shown on Calling page whenever you open it.

Simple enough? Good. Because now we will be learning some more cool stuff with Templates.

The first thing you now need to know that you can use a template even without putting it into the Template namespace. But then, you will have to mention the namespace of whichever template you are using. For example, the table that you see below is a template at User:TheOriginalSoni/Templates adoption 1. Then how did I get it to work? By using the full name of the template-.

Here is a table of what happens when you call these templates-

The second thing to know is parameters. For some templates, you might want to change the way it displays for different values you specify. For that, you use parameters while calling the template. To use that, you simply call your template this way -. This code will call the template, but with the parameter "1" getting the value of "foo" when called. While making the template, you can give the parameters names or numbers. When you use names, you have to write the parameter name while calling it before specifying its value. will now give a value of "foo" to the parameter "name". When using numbers, you may choose to skip the parameter's name, but you can't do that for named parameters.

In the template page, there are several codes you can add to do some special things, including adding a parameter. This table shall explain what they do.

Some templates can be used with parser functions such as #if: These functions to apply certain conditions to the code and make the template appear differently based on what the function is. These functions can help you to create some rather advanced templates, but often get exceedingly complicated and should only be edited by those users who fully understand how they work. Since these are rather complex, they will not be covered in your exam, but if you'd like we can cover them after we've completed the other topics.

The last thing you need to know about templates is Substitition. Substitution, or "subst'ing" a template replaces the curly braced call by the actual template text. To do this, add the code "subst:" at the beginning of the call:. When this is done, the MediaWiki software will replace that call with the template's code on saving the page. This causes the template to lock in place - however it was when you called it, is how it's going to be from then on. The page at WP:SUBST gives details on what templates should, must, or must not be substituted. When writing templates, it can also be useful to enclose the subst: code within tags. See below.