User Defined Templates

From TDGwiki

Jump to: navigation, search

Author: Zantetsuken

Contents

General

Templates can be used to simplify many things. For example, the Clan TDG Member List is made by transcluding a few templates together. By doing this, you can use the same information in multiple places without having to copy and paste things over. This has many benefits because by updating the template, you update every single page that has been transcluded!

Creating a Template

Creating a template is very easy. Simply go to wiki/Template:YourTemplate, edit and save. Of course, change YourTemplate to something more descriptive.
Let's take a look at an existing template, Template:Shaman. It contains a list of all the members of Clan TDG with the Shaman rank. This is a very simple example: the template only contains text with some Wiki markup for the image and the links. More dynamic things can be done with templates and will be discussed later in this tutorial.

Using a Template

By using I mean transcluding. Transcluding, as mentioned, will display the information from the template. Let's transclude Template:Chieftain into this tutorial:

RankChieftain.gif

Transcluding is very easy. The following code will transclude YourTemplate into a page:
{{YourTemplate}}
In our case, {{Chieftain}} was used. Edit the Chieftain transclusion in this page to another rank and see transclusion in action.

Dynamic Templates

Dynamic templates are very similar to functions. You create them with variables and then pass arguments into them.

Creating a Dynamic Template

I don't know if Dynamic Template is an "official" Wiki term. Creating a Dynamic Template is the same as creating a regular Template as explained above. What's different, though, is the coding.

What Makes a Dynamic Template Dynamic

Arguments get passed into a Dynamic Template which refer back to a variable. To create a variable, enclose a word like this:
{{{Variable}}}
As an example, check out the code for Template:TutorialTemplate. It only contains one variable, {{{Variable}}}. We'll be using this in the next section of the tutorial to see how variables work.

Passing Arguments into a Dynamic Template

Whenever you want to pass an argument into a template, you need to keep in mind the names of the variables you created. Let's pass the word Test into our template using the following code:
 {{ TutorialTemplate
 | Variable=Test
 }}
And it will produce...
Test
Let's take a look at each line separately.
  • Line 1: {{ TutorialTemplate
  • We've seen {{ before from transclusion
  • TutorialTemplate tells Wiki which template you are sending arguments to
  • Line 2: | Variable=Test
  • | lets the Wiki know that it has more code to evaluate before finishing the transclusion
  • Variable=Test sets Variable to Test
  • Line 3: }}
  • }} tells Wiki to stop transcluding
Now, this example is impractical. Dynamic Templates aren't supposed to be used for generating single words. Dynamic Templates should be used for generating things that should follow a similar format. Another reason why you may want to use Dynamic Templates is to make things more simple for yourself in the long run.

My Dynamic Templates

For usage instructions and a list of variables required for each template, refer to their individual pages:

Conclusion

Templates are extremely useful for saving time and creating a standard. Templates will allow you to create pages faster and easier because all you need to do is pass some arguments. The formatting is already taken care of and reduces the tedious work of copying, pasting and editing.
Navigation
Clan TDG

Main About the Clan Join.gif Clan TDG Members Community Events Friends Links Forum.gif

Resources

Maps Tutorials Tools Custom Skins, Icons, & Models

Wiki

Website Feedback Community Portal Recent Changes Jump to a Random Page Wiki Help

Toolbox
Clan TDG

Main About the Clan Join.gif Clan TDG Members Community Events Friends Links Forum.gif

Resources

Maps Tutorials Tools Custom Skins, Icons, & Models

Wiki

Website Feedback Community Portal Recent Changes Jump to a Random Page Wiki Help

LANGUAGES
Clan TDG

Main About the Clan Join.gif Clan TDG Members Community Events Friends Links Forum.gif

Resources

Maps Tutorials Tools Custom Skins, Icons, & Models

Wiki

Website Feedback Community Portal Recent Changes Jump to a Random Page Wiki Help