Template:Namespace detect
{{#switch:
{{#if: | {{{demospace}}} | {{#if: | {{#ifeq:| | talk | }} | {{#ifeq:template|template talk | talk | template }} }} }}
| main | = | talk = | user = | project = | file | image = | mediawiki = | template = | help = | category = | book = | extension = | other | #default =
}}
|
This is the {{namespace detect}} meta-template.
It helps other templates detect what type of page they are on.
It detects and groups all the different namespaces used on MediaWiki.org into several types:
- main = Main/article space, as in normal MediaWiki.org articles.
- talk = Any talk space, such as page names that start with "Talk:", "User talk:", "File talk:" and so on.
- user, project, file, mediawiki, template, help, category, and book = The other namespaces except the talk pages.
- other = Any namespaces that were not specified as a parameter to the template. See explanation below.
For backwards compatibility this template also understands the old name image for file. But using image is now deprecated.
Note! For most usage cases it might be better to use the simpler namespace detection templates. (See the see also section below.) Since this template is more prone to human errors such as misspelling the parameter names.
Usage
This template takes one or more parameters named after the different page types as listed above. Like this:
{{namespace detect | main = Article text | talk = Talk page text | other = Other pages text }}
If the template is on a main (article) page, it will return this:
- {{#switch:
{{#if:main | main | {{#if: | {{#ifeq:| | talk | }} | {{#ifeq:template|template talk | talk | template }} }} }}
| main | = Article text | talk = Talk page text | user = Other pages text | project = Other pages text | file | image = Other pages text | mediawiki = Other pages text | template = Other pages text | help = Other pages text | category = Other pages text | book = Other pages text | extension = Other pages text | other | #default = Other pages text
}}
If the template is on any other page than an article or a talk page it will return this:
- {{#switch:
{{#if: | {{{demospace}}} | {{#if: | {{#ifeq:| | talk | }} | {{#ifeq:template|template talk | talk | template }} }} }}
| main | = Article text | talk = Talk page text | user = Other pages text | project = Other pages text | file | image = Other pages text | mediawiki = Other pages text | template = Other pages text | help = Other pages text | category = Other pages text | book = Other pages text | extension = Other pages text | other | #default = Other pages text
}}
The example above made the template return something for all page types. But if we don't use the other parameter or leave it empty then it will not return anything for the other page types. Like this:
{{namespace detect | file = File page text | category = Category page text | other = }}
On any pages other than file and category pages the code above will render nothing.
- {{#switch:
{{#if: | {{{demospace}}} | {{#if: | {{#ifeq:| | talk | }} | {{#ifeq:template|template talk | talk | template }} }} }}
| main | = | talk = | user = | project = | file | image = File page text | mediawiki = | template = | help = | category = Category page text | book = | extension = | other | #default =
}}
By using an empty parameter you can make it so the template doesn't render anything for some specific page type. Like this:
{{namespace detect | main = | other = Other pages text }}
The code above will render nothing when on mainspace (article) pages, but will return this when on other pages:
- {{#switch:
{{#if: | {{{demospace}}} | {{#if: | {{#ifeq:| | talk | }} | {{#ifeq:template|template talk | talk | template }} }} }}
| main | = | talk = Other pages text | user = Other pages text | project = Other pages text | file | image = Other pages text | mediawiki = Other pages text | template = Other pages text | help = Other pages text | category = Other pages text | book = Other pages text | extension = Other pages text | other | #default = Other pages text
}}
Demospace and page
For testing and demonstration purposes this template can take two parameters named demospace and page.
Demospace understands any of the page type names used by this template, including the other type. It tells the template to behave like it is on some specific type of page. Like this:
{{namespace detect | main = Article text | other = Other pages text | demospace = main }}
No matter on what kind of page the code above is used it will return this:
- {{#switch:
{{#if:main | main | {{#if: | {{#ifeq:| | talk | }} | {{#ifeq:template|template talk | talk | template }} }} }}
| main | = Article text | talk = Other pages text | user = Other pages text | project = Other pages text | file | image = Other pages text | mediawiki = Other pages text | template = Other pages text | help = Other pages text | category = Other pages text | book = Other pages text | extension = Other pages text | other | #default = Other pages text
}}
The page parameter instead takes a normal pagename. It makes this template behave exactly as if on that page. The pagename doesn't have to be an existing page. Like this:
{{namespace detect | user = User page text | other = Other pages text | page = User:Example }}
No matter on what kind of page the code above is used it will return this:
- {{#switch:
{{#if: | {{{demospace}}} | {{#if:user:example | {{#ifeq:user|user talk | talk | user }} | {{#ifeq:template|template talk | talk | template }} }} }}
| main | = Other pages text | talk = Other pages text | user = User page text | project = Other pages text | file | image = Other pages text | mediawiki = Other pages text | template = Other pages text | help = Other pages text | category = Other pages text | book = Other pages text | extension = Other pages text | other | #default = Other pages text
}}
It can be convenient to let your template understand the demospace and/or page parameter and send it on to the {{namespace detect}} template. Then do like this:
{{namespace detect | main = Article text | other = Other pages text | demospace = {{{demospace|}}} | page = {{{page|}}} }}
If both the demospace and page parameters are empty or undefined then the template will detect page types as usual.
Parameters
List of all parameters:
{{namespace detect | main = ... | other = | demospace = {{{demospace|}}} / main / talk / user / project / file / mediawiki / template / help / category / book / other | page = {{{page|}}} / User:Example }}
Note: Empty values to the "main" ... "book" parameters have special meaning.
Technical details
If you intend to feed tables as content to the numbered parameters of this template, then you need to know this:
Templates do have a problem to handle parameter data that contains pipes "|
", unless the pipe is inside another template {{name|param1}}
or inside a piped link [[Help:Template|help]]
. Thus templates can not handle wikitables as input unless you escape them by using the {{!}} template. This makes it hard to use wikitables as parameters to templates. Instead the usual solution is to use "HTML wikimarkup" for the table code, which is more robust.
|