Many userboxes and other templates automatically add the pages on which they appear to various categories. This feature is not always desirable, and the process of disabling or suppressing automatic categorization is referred to as category suppression in templates. This guide describes a few different methods of suppressing automatic categorization and provides examples for each method. There are no policies or strict guidelines regarding category suppression; however, this guide describes the de facto methods used to implement category suppression on the English Wikipedia.

Background information[edit]

Many templates and userboxes are designed to automatically add pages into one or more categories. There are many reasons why this might be beneficial. Userboxes can group users in various Wikipedian categories based on interests. WikiProject headers group related pages to make it easier for WikiProject members to locate them. Other templates flag articles for certain actions by adding the articles to administrative categories.

This can be a really useful and powerful feature, but it can also be a little confusing if someone wants to display the template somewhere other than where it was originally intended, such as on a help page or in a template gallery. The help page or gallery would be flagged like any other page on which the template appears, and this is often not desirable. For example, a page demonstrating a deletion template should not be flagged for deletion itself. It is preferable to suppress the automatic categorization of the page in that instance. This is referred to as category suppression.

Within the template itself, it is fairly easy to suppress such categorization problems using the <includeonly> and <noinclude> markup. However, those features do not help when displaying the template as an example on a help page or in a gallery.

At the expense of a little extra processing on the server and making the template code a little bit more difficult for humans to read, templates or a simple parser function can suppress automatic categorization in certain namespaces or anywhere when particular template attributes are used.

Several different methods of category suppression developed simultaneously over the years, so there is no single or "best" method of achieving category suppression. Some methods work better in some situations and other methods work better in other situations. Template designers are free to choose from any of the following methods to suppress automatic categories, but are requested to clearly document which method is used within the template documentation. New templates are requested to follow the preferred techniques (when multiple techniques achieve the same result). Older templates that are not heavily used can also be modified to use the preferred techniques, too. It is not worthwhile to adapt heavily used templates to use the preferred techniques, unless there is another compelling reason to modify the template.

Usage[edit]

Templates that use namespace-based suppression do not require any configuration by an editor to suppress automatic categorization outside of the intended namespace (e.g., article templates will not categorize talk pages or user pages).

Attribute-based suppression templates use either |nocat=true (preferred) or |categories=no (alternative) to suppress automatic categorization. Anywhere that categorization should be suppressed, just add |nocat=true or |categories=no as the last attribute for the template, and (assuming the template is implemented correctly), the template will not add the page to any categories. Refer to the documentation for each template to determine which of the two attributes to use.

Category suppression methods[edit]

Category suppression techniques fall into the following methods:

  1. Based on the namespace of the page, categorization is enabled or suppressed
  2. Template attributes are passed to the template to specifically suppress automatic categorization of pages
  3. Blended suppression uses both of the other methods together to meet complex needs
  4. Using a blacklist of pagenames that should not be categorized - e.g. see Template:Category handler

Namespace-based suppression

Overview

Templates designed to be added only to certain types of pages (articles, talk pages, categories, other templates, project pages, etc.) are likely to benefit from this method the most. Using this method, templates can automatically detect the type of page they are on, and only categorize pages that are in the correct namespace. For example, a template that flags articles needing additional references can use this method to only categorize articles and suppress categorization everywhere else the template appears, such as on template documentation pages.

Pros

Cons

Examples are given below.

Attribute-based suppression

Overview

Automatic categorization is always turned on in these templates by default. Any page on which the template appears is automatically categorized unless one of two special attributes is passed to the template. This is a good choice for templates that are used across multiple namespaces. For example, a typing-aid template that could be used in articles, talk pages, project pages, user pages, and portals might be a good choice.

Pros

Cons

Examples are given below.

Blended suppression

Overview

This is the most versatile and complicated method of suppressing categories. Using both of the previous techniques, you can combine namespace-based default categorization/suppression with attributes to change the default action on a case-by-case basis. This should not be necessary for most templates, but may be useful in some of the more complex meta-templates that combine features from several related templates into a single, large template. It adds an extra degree of difficulty in designing and maintaining the template that should only be considered for templates that are already complex (and unlikely to be edited by novice templaters) or where the two previous techniques do not provide enough control.

Pros

Cons

Examples are given below.

Wrapper templates

Category suppression examples[edit]

Namespace-based suppression examples

This method is automatic and needs no parameter to invoke the suppression.

Using the ((Main other)) family of templates

If your template categorizes in template space, then you need to surround the categorization code with <includeonly></includeonly>, otherwise your template itself will be categorized.

There are also ((user other)), ((wikipedia other)), ((file other)), ((help other)), ((category other)) and ((portal other)) to handle the other namespaces.

Using the ((Namespace detect)) template

If automatic categorization/suppression is desired in multiple namespaces or if you need different categories to be used in different namespaces, use the powerful ((Namespace detect)) template:

<includeonly>((Namespace detect
| main = [[Category:Article category]]
| talk = [[Category:Talk category]]
| template = [[Category:Template category]]
| other = <!-- Don't categorize when not in main, talk, or template space --> ))
</includeonly>

Using parser functions

Using the ((Main other)) family of templates is the easiest way to enable namespace-based category suppression, but you can also use the #ifeq or #switch parser functions to accomplish the same thing.

((#ifeq:((NAMESPACE))|((ns:0))|[[Category:Article category]]|<!-- Don't categorize when not in main (article) space. -->))

<includeonly>((#switch:((NAMESPACE))
| =[[Category:Article category]]
| Talk = [[Category:Talk category]]
| Template = [[Category:Template category]]
| #default = <!-- Don't categorize when not in main, talk, or template space --> ))
</includeonly>

Attribute-based suppression examples

The following technique is the recommended standard technique for the attribute-based category suppression method.

In other words, setting "nocat" to anything other than "false" (even to nothing) will result in no categorization.

Unfortunately, category suppression attribute names were not previously standardized, resulting in several variations. The following attribute names that are commonly used to indicate when category suppression should be performed are:

An example using |nocat= where the default is to automatically categorize
<includeonly>((#ifeq: ((lc:(({nocat|false))))} | false |
[[Category:Example]]
|<!-- Category suppressed -->))</includeonly>
An example using |categories=no to suppress categorization
<includeonly>((#ifeq: ((lc:(({categories))))} | no ||
[[Category:Example]]))</includeonly>
Implementation notes
The category= attribute

|category= is used by some templates to avoid having to use the #ifeq parser function. Since the attribute name "category" is commonly used for other purposes in many templates (as is "categories" to a lesser degree), "category" is not a recommended attribute name for this purpose. For that reason and others, this technique is not discussed here. Note that |nocat= can serve exactly the same purpose and is the recommended alternative.

Blended suppression examples

Blended suppression combines both attribute-based and namespace-based suppression methods within a single template. Because it combines both methods, the complexity is doubled. Please be sure that you fully understand both of the other methods before attempting to use the blended method in a template.

There are multiple ways that blending can be accomplished. The following example is the way that Willscrlt prefers to implement blended suppression (which should work for most cases and is recommended for consistency).

The process is to first check for attributes that would indicate that categories should be suppressed. If category suppression is requested by the attribute, it overrides any default categorization based on the namespace. If no attribute specification is found, then use the default categorization based on the namespace. If the attribute explicitly requests category suppression not be used, then use the default categorization based on the namespace, unless the default is to not categorize. If the default is to not categorize, then use the demospace attribute to override the default and display the category anyway. Together, these options give template developers considerable control over automatic categorization and category suppression at the expense of more complex template code.

A complete example

<includeonly>((#ifeq: ((lc:(({nocat|false))))} | false |
((Namespace detect
| main = [[Category:Article category]]
| talk = [[Category:Talk category]]
| template = [[Category:Template category]]
| other = ((#ifeq: ((lc:(({nocat|false))))} | true |
[[Category:Other category]]
| <!-- Unless nocat=true, don't categorize when not in main, talk, or template space --> ))
))

|<!-- Category suppressed by nocat attribute -->))</includeonly>

Supporting older implementations in meta templates[edit]

If you are attempting to create a meta template (a template that combines the features of two or more templates into a single template), you may need to support more than one method of category suppression, because editors may use different methods of requesting category suppression depending on the original template syntax.

The following method checks for either of the two common attributes (|nocat=true and |categories=no) and suppresses automatic categorization if either is set to suppress.

<includeonly>((#ifexpr: ((
#ifeq: ((lc:{))} | true | 1 | 0 ))
+ ((
#ifeq: ((lc:(({categories|yes))))} | no | 1 | 0 ))
< 1 |

[[Category:Example]]
|<!-- Category suppressed -->))</includeonly>

See also[edit]