Template:Main talk other/doc

This is the main talk other meta-template.

This template is used inside other templates that need to behave differently (usually look differently) depending on what type of page they are on. It detects and groups all the different namespaces used on Wikipedia into three types:


 * main = Main/article space, as in normal Wikipedia articles.
 * talk = Any talk space, such as page names that start with "Talk:", "User talk:", "File talk:" and so on.
 * other = All other spaces, such as page names that start with "User:", "File:", "Wikipedia:" and so on.

Basic usage
This template usually takes three parameters, and returns one of them depending on which type a page belongs to. Like this:



If the template is on a main space (article) page, it will return this:



If the template is on any talk page, it will return this:



If the template is on any other page (such as this template page and its doc page), it will return this:



If you only feed a parameter for one or two of the types then this template returns an empty string for the rest of the types. That is, if it for instance is used in one of these ways:



Then it doesn't render anything in mainspace and other space.



If this template is used without any parameters or only fed empty parameters (empty strings), then it returns an empty string. That is, then it renders nothing.



For testing and demonstration purposes these templates can take a parameter named demospace: if it has any of the values main, talk or other it makes the template behave as if it is on a page of that type; if the parameter is empty or undefined, the actual page type determines the result.

Usage example
This example creates a message box, but these templates can of course be used for many other things than message boxes. This example uses numbered parameters and HTML tables, for the reasons why see the technical details section below.

Which renders like this:

Let's see how it looks on talk pages. So we change the first line in the code to this:

{{main talk other|demospace=talk

This is how it will render on any talk page:

{{main talk other|demospace=talk }}
 * 1 = This messagebox should not be used in articles.
 * 2 = {{tmbox|text=Talk page notice}}
 * 3 = {{ombox|text=Other pages notice}}

And now let's test it for article pages:

{{main talk other|demospace=main

This is how it will render in an article:

{{main talk other|demospace=main }}
 * 1 = This messagebox should not be used in articles.
 * 2 = {{tmbox|text=Talk page notice}}
 * 3 = {{ombox|text=Other pages notice}}

Additional code
Too make this example complete, here is the rest of the code that is needed to make it a fully equipped template:

The line " " means that your template also will understand the demospace parameter. That means you can demonstrate the different appearances of your template in the documentation for your template.

CSS namespace detection
CSS code can be used instead of these templates to detect namespaces. This can be used for those things that can be coded as CSS, such as colors and borders.