Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Template:Category handler

From FlightGear wiki
Jump to: navigation, search


The following template description is not displayed when the template is inserted in an article.

Goal

This template can be used by other templates to make automatic categorization more flexible and to suppress the categorization in certain circumstances. It can just as well as categories instead be used to add texts to pages depending on the namespace.

In simpler cases it might be advantageous to instead use {{namespace detect}} instead and in cases when a template only need to categorize pages that in one single namespace or in any namespace but one single namespace, please use the {{* other}} templates instead.

Usage

{{category handler
| category
| subpage =
| 1 =
...
| 10 =
| all =
| main =
...
| other =

| nocat =

| page =
}}

All parameters are optional.

category
Category or text to add to a page.
subpage
If suppage=no subpages will not be categorized, and if subpage=only only subpages will be categorized.
1..10
Numbered parameters for categories or text that can be used in combinations in different namespaces.
all
Category or text that will be used in all namespaces.
main, talk, user, flightgear wiki, project, file, mediawiki, template, help, category, portal, other
Categories, text or numbered parameters that will be used in that namespace.
nocat
If nocat=true pages are not categorized, if nocat=false pages are always categorized disregarding the blacklist, and if nocat is empty or undefined pages are categorized as per default. Use nocat = {{{nocat|}}} to forward this behaviour to a template.
page
Wiki page to be used for demonstration and debugging purposes. Use page = {{{page|}}} to forward this behaviour to a template.

Examples

Simple example

All pages the template below will be put on will be categorized unless nocat=true is used.

{{some template
| text = Some text
}}{{category handler
| [[Category:Some category]]
| nocat = {{{nocat|}}}                     <!-- Needed for "nocat=true" and "nocat=false" to work. -->
}}

Category suppression

Categorisation can be suppressed, so that pages are only categorised if a template is put in certain namespaces.

In the example below only pages in the main (article) and talk namespaces are categorized and the categorization can be disable by using nocat=true when using the template.

{{some template
| text = Some text for articles and article talk pages
}}{{category handler
| main = [[Category:Some category]]        <!-- Category added to pages in the main (article) namespace. -->
| talk = [[Category:Some other category]]  <!-- Category added to pages in the talk namespace. -->
| nocat = {{{nocat|}}}                     <!-- Needed for "nocat=true" and "nocat=false" to work. -->
}}

Advanced example

Below is a more advanced example using among other things the numbered parameters to feed some of the other parameters:

{{some template
| text = Some text
}}{{category handler
| main = [[Category:Somecat1]]             <!-- Category added to pages in the main (article) namespace. -->
| 1 = [[Category:Somecat2]]                <!-- Category added to pages in the help and user namespaces. -->
| help = 1
| user = 1
| talk =                                   <!-- No category added to pages in the talk namespace. -->
| other = [[Category:Somecat3]]            <!-- Category added to pages in all the other namespaces. -->
| nocat = {{{nocat|}}}                     <!-- Needed for "nocat=true" and "nocat=false" to work. -->
}}

Subpages

It is also possible to suppress categorization of sub-pages using subpage=no as well as to only categorize sub-pages using subpage=only.

{{category handler
| subpage = no                             <!-- No category added to sub-pages. -->
| user = [[Category:Some category]]        <!-- Category added to pages in the user namespace. -->
| nocat = {{{nocat|}}}                     <!-- Needed for "nocat=true" and "nocat=false" to work. -->
}}

The "nocat" parameter

This template have a nocat parameter:

  • If nocat=true then this template does not categorize.
  • If nocat is empty or undefined then this template categorizes as usual.
  • If nocat=false this template categorizes even when on blacklisted pages.

Templates that use {{category handler}} should forward nocat, so that they too understand nocat. Adding "nocat = {{{nocat|}}}" as shown in the examples does that.

The "page" parameter

When testing, debugging or demonstrating a template the page parameter might be useful, like in the below example. The page does not have to exist and the blacklist works just as usual. If page is undefined or empty the page the template is used on will be used instead.

{{category handler
| main = Category:Some category            <!-- This and the following line will not categorize, only show text -->
| talk = Category:Some talk category
| nocat = {{{nocat|}}}                     <!-- Needed for "nocat=true" and "nocat=false" to work. -->
| page = User talk:Example                 <!-- Using the template as if it was put on the page "User talk:Example" -->
}}

Templates should preferably forward the page parameter by adding "page = {{{page|}}}" as below:

{{category handler
| main = Category:Some category            <!-- This and the following line will not categorize, only show text -->
| talk = Category:Some talk category
| nocat = {{{nocat|}}}                     <!-- Needed for "nocat=true" and "nocat=false" to work. -->
| page = {{{page|}}}                       <!-- For testing. -->
}}

Related templates