Template:Namespace detect

From FlightGear wiki
Jump to navigation Jump to 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 alter their behaviour depending on the namespace of the page they are put on.

The altered behaviour could for example be to use a different style, to show different text and/or to alter or suppress categorisation.

Note! In many cases using the simpler namespace templates would be preferable.

Usage

{{namespace detect
| main      = 
| talk      = 
| user      = 
| project   = 
| file      = 
| mediawiki = 
| template  = 
| help      = 
| category  = 
| portal    = 
| howto     = 

| other     = 

| demospace = 
| page      = 
}}

All parameters are optional and if none is used an empty string will be returned.

main...howto
Parameters with content to use for those namespces.
other
Parameter with content to use in any other namespaces.
demospace
Namespace override, can be any of the above namespaces, main...howto and other. If not used the namespace of the page the template is placed on will be used.
page
Other page to use instead of page the template is placed on. If not used the namespace of the page the template is placed on will be used.

Examples

General usage

The template takes parameters named after the namespaces, except for project instead of flightgear wiki.

{{namespace detect
| main      = Text in article pages
| talk      = Text in talk pages
| other     = Text in other pages
}}

Demospace

The demospace parameter is helpful when testing or demonstrating a templates in other namespaces than the one of the pages they are placed on.

The below example would display "Text in article pages" since demospace = main.

{{namespace detect
| main      = Text in article pages
| talk      = Text in talk pages
| other     = Text in other pages
| demospace = main
}}

Page

The page parameter is useful when you want to test a template against another page than the one it is placed on.

{{namespace detect
| main      = Text in article pages
| talk      = Text in talk pages
| other     = Text in other pages
| page      = Talk:Main
}}

Using with parameters within a template

Using named parameters the template can also be used with parameters from a surrounding template. For example like below, though the parameters could just as well have other names or be numbered parameters.

{{namespace detect
| main      = {{{main|}}}
| talk      = {{{talk|}}}
| other     = {{{other|}}}
| demospace = {{{demospace|}}}
}}

Category suppression

This template can be used for category suppression to suppress automatic categorisation unless a page is in a certain namespace. For easier cases us the "other" templates instead, for example {{main other}} and {{talk other}}, and for more advanced cases you can use the {{category handler}} template.

{{#ifeq: {{{nocat|}}} | true <!-- Makes it possible to entirely suppress categorisation using nocat = true. -->
 |
 | {{namespace detect
   | main      = [[Category:Some category]]
   | howto     = [[Category:Some other category]]
   | demospace = {{{demospace|}}}
   | page      = {{{page|}}}
   }}
}}

Related templates

The "other" templates