Forum:Making a template that automatically adds categories? Read this.

From Tardis Wiki, the free Doctor Who reference
Indextech notes → Making a template that automatically adds categories? Read this.
Spoilers are strongly policed here.
If this thread's title doesn't specify it's spoilery, don't bring any up.

If you've ever made a template which automatically adds categories, you know there's a little problem that sometimes happens. You can easily end up putting the template itself into the category the template populates.

Imagine you had the template, {{Time Lord}} and it put pages into category:Time Lord. Chances are, you've probably got template:Time Lord in category:Time Lord, unless you've manually coded around the problem.

Now we've got a much easier way round the problem. In your template, just use {{cat}}. So, if you wanted your template to put pages into category:Time Lord, you'd just add {{cat|Time Lord}} to your code. That's it! Super easy.

Here's a live example of a template Skittles the hog recently made. (Note that the vertical spacing is for clarity of illustration. Please don't format your code this way on a "live" template>)

<includeonly>

<sup>[[:template:disputed|['''disputed''' statement]]]</sup>

{{cat|Articles with statements that are disputed}}

</includeonly>

<noinclude>

{{documentation}}

[[Category:Maintenance templates|{{PAGENAME}}]]

</noinclude>

If you have any questions, please feel free to get in touch with me.
czechout<staff />   22:16:30 Mon 29 Aug 2011