SMITE Esports Wiki:Tutorial/Templates

Introduction
Templates are the bread and butter of our wiki, and you've seen them all over the place even if you don't realize it -- ci, team, TabsHeader, Box, Col, and scoreboards are all examples of templates. Actually, "template" is a bit of a misnomer - a better name for templates would be "functions." When you make a template, you are putting a bunch of wikitext that you don't want to type out over and over and over again, and making it easily insertable into any place in the wiki. Templates can also reference each other -- for example, TabsHeader references Tabs, which in turn references TabsTop. Templates can vary from very simple to extremely complex.

If you're familiar with programming and/or web design, you'll probably be able to figure out a lot of this on your own, but read over this page and bookmark the help page on parser functions to help you out with syntax anyway. And if you're not, then this page serves as a gentle introduction to templates and what they can do (hint: it's pretty much anything).

Recognizing Templates
How do you know when something is a template? Well, technically any page can be used as a template (more on that later). But in the vast majority of cases, a template will be hosted at a page with a URL like .../wiki/Template:[TemplateName]. When you're editing a page, you can tell that something is a template if it starts with. When the template is over, you will see the closure,.

After the, you will see a word or words, for example   or   or. That word or words is the title of the template, and the same as the rest of the URL after Template: where the template code is located. If it's a simple template, that might be it. But usually there will be at least one variable defined. Let's look at the ci template again. If you write, you see. The  |Thor  tells the template what god to use.

Using Templates
Now that we can recognize templates and their parts, how do we use them? Some templates, like ci will have extensive documentation that you can see when you navigate to their page (remember a template's URL is always .../wiki/Template:[TemplateName]). If you're not sure what to do, seeing if the template in question has documentation can be a great place to start. However, frequently we make templates that don't have documentation -- while this isn't the best practice, we make a lot of on-the-fly templates, and writing documentation for each one would be very time-consuming. So if there's no documentation, how do you figure out what a template does?

The best way is always going to be to look at an example of the template in action. If you're trying to use a template that you don't understand already, chances are that you're editing a page that includes other instances of that template. Most templates will have descriptive names for their variables, or at least you can look at the values that the variables have and figure out what you're supposed to put.

What if you can't find any instances of the template you need to use? Turns out, there's an easy way to look for them! Go to the template's page (Template:TemplateName). Then, find What Links Here under Tools in the sidebar and click it. You'll be taken to a page like this one, where you can see a list of pages that include the template in question. If it says "(transclusion)" after the link, then the template is used in that page. Click to the page that uses the template, go to Edit, and search for the template name within the page.

Still not sure? Let's look at the template code itself. Let's first use a relatively simple example: The code for the tabs used in this tutorial (TutorialTabs).



That looks pretty familiar - in fact, it's just the TabsHeader template with some other stuff added before and after it, and instead of |This=1 or something, it says |This=. In the source code for templates, denotes that something will be a variable when you use the template in another page. There's four things that you can see between tags, and they indicate what type of variable it is:
 * * Technically, what you are doing here, is the same as above with the default value of 2; it's just that the default value is nothing.

Includeonly, Onlyinclude, and Noinclude
Let's go back to our TutorialTabs template, the template we looked at above. What's the deal with it saying   at the start and then    at the end? Here's what's going on.

Fundamentally, templates are no different from any other page in the wiki.
Having a sentence as a section heading is kind of weird, and the only reason I've done it here is that this is a really, really, really important concept. Just because a template is named Template:TemplateName doesn't mean that it's special in any way. When you call a template using  , the wiki assumes that you're looking for something in the Template namespace by default, but if you want you can call something in any namespace!

Remember back when we wrote "Hello, world!" on a page back in Task 1?

It works exactly the same as any other template, inserting code from one place to another.

So! Where do Includeonly, Onlyinclude, and Noinclude come in? Go look at a template called TeamsVsAlign. When you go to the page, you see some documentation about the code, but you don't actually see the code that comprises the template. Why not? What stops you from seeing it, and what stops the documentation from being inserted along with the rest of the template code whenever you use the template?

Transclusion
Transclusion is the inclusion of text from one page to another, accomplished by referencing the one page within the other. You can read about transclusion here. Using a template is the most common form of transclusion.

The meanings of  ,  , and   become clearer if we put them into sentences involving transclusion.
 * Include this code only when transcluding (and not when displaying normally).
 * Only include this part of the code when transcluding.
 * No include this code when transcluding.

Okay, let's get back to TeamsVsAlign. Here's its code:    vs 	

So we have, and then the code that we want it to use, using two variables (unnamed, optional variables), and then a. So all of the code between those two tags is not displayed at Template:TeamsVsAlign but is displayed whenever the code is embedded.

Then after that, we have -- so we're going to display the documentation at Template:TeamsVsAlign, but not when we use the template elsewhere. (What exactly is documentation? We'll go over that in a bit.)

Writing Templates
Templates can range from very simple (such as a template to create one row of tabs, like TutorialTabs, which is used for these pages) to much more complicated (such as RosterChangeLine, the template used to track roster swaps). We'll go over the basics here, and if you want to go more indepth, check out [Help:Templates MediaWiki's help page] and a more in-depth page. You can also contact Chris, our MediaWiki developer.

When should you create a template?

 * When you need to enter a very long piece of code many times with slightly different parameters each time
 * When you need to enter identical code in several places that's subject to change

This applies to pretty much all tournaments that have tabs at the top. There are always multiple pages for the coverage that we have, including Scoreboards, Picks and Bans, etc. And if there's a new tournament added in the series, or if we decide to add additional content, or any other change that needs to be made to the tabs, we don't want to have to change that on every single page -- so we make a template for it.

How to name a template
Please don't name your template anything like "Template1," "RheingoldRiver's Template for Worlds Tabs," or "Blueberry Spicehead." Give it a descriptive title that gives users a decent idea of what it's for. Latest_God is for the latest god that was released. EU_SPL_Season_2_Tabs are tabs for the season 2 European SPL. TutorialTabs are tabs for the tutorial section.

Conventions to follow:
 * If your template is primarily a TabsHeader with a variable as the number, make the name ___Tabs, where ___ is a reasonable name for the event or set of pages where the tabs will go.
 * If your template exists to make formatting easier but isn't necessarily going to be used only in the capacity for which you're making it, give it a name based on what it does not why you made it -- TeamsVsAlign rather than WorldsStatsTableEntry is a good example.
 * Multiple words should be combined with a capital at the start of each new entry.
 * Try to make the name as short as possible without losing information.

Starting your Template
Start out with 

As discussed previously, your code will go in between the includeonly tags. Write the code that you want your template to have, keeping in mind what we went over with variables - you will probably want to have at least one variable in most cases.

Documentation
The last part is documentation. While it's not required, we request that you always document your templates, even if it's something as simple as "Tabs for the Editing Tutorial." (which is the documentation for TutorialTabs). Fortunately, making documentation is very easy, and you already did half of it when you wrote at the end of your code!

Simply go to .../wiki/Template:TemplateName/doc and write your documentation there, then press save. Then go back to .../wiki/Template:TemplateName and Refresh the page using the button in the dropdown menu next to the search bar. Done!

Your First Template
Let's write a template! Normally, you would put the template at, but since we try to keep that namespace uncluttered, make it at. You'll make a couple versions of the template.

Version 1: No Variable
Make the following template:  Hello, World!

Now make a page called  and write:  You should see "Hello, World!" written.

Version 2: Required Variable
You can choose to make separate templates at, etc, or not. For convenience of writing, we'll assume they're all in the same place. Write the following code:

 My favorite god is.

Now if you write, you will see "My favorite god is ."

Version 3: Optional Variable
Same thing, but instead of, try. Now you can write  and it will show "My favorite god is ."

Version 4: #if
This is slightly more advanced, but still pretty basic. The help article on parser functions should help you understand how the  works.



We've made the same thing as the optional variable above!

These are obviously extremely simple templates, and as you learn more you will make much more complicated ones, using,  , and  , and other parser functions. It can be a lot of fun!