Changes
Jump to navigation
Jump to search
m
→CSS namespace detection: clean up per WP:CAT#T and WP:AWBREQ add template:Sandbox other
{{Documentation subpage}}
<!-- PLEASE ADD CATEGORIES WHERE INDICATED AT THE BOTTOM OF THIS PAGE -->
This is the {{tl|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 [[Wikipedia:Namespace#Enumeration|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.
This page is also the documentation for some other templates:
* {{tl|main talk other flex}} – It works exactly the same, but it has some minor internal differences. Read more about that [[#Technical details|below]].
* {{tl|main other}}, {{tl|talk other}}, {{tl|file other}} and {{tl|category other}} – Simpler versions that only differentiate between one type of page and all other.
== Basic usage ==
This template usually takes three parameters, and returns one of them depending on which type a page belongs to. Like this:
:{{tlc|main talk other|Article text|Talk page text|Other pages text}}
If the template is on a main space (article) page, it will return this:
:{{main talk other|demospace=main|Article text|Talk page text|Other pages text}}
If the template is on any talk page, it will return this:
:{{main talk other|demospace=talk|Article text|Talk page text|Other pages text}}
If the template is on any other page (such as this template page and its doc page), it will return this:
:{{main talk other|Article text|Talk page text|Other pages text}}
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:
:{{tlc|main talk other||Talk text}}
:{{tlc|main talk other||Talk text|}}
Then it doesn't render anything in mainspace and other space.
:{{main talk other||Talk text|}} <!-- Don't remove this line. It is supposed to render nothing. But leave it so we see if it fails. -->
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.
:{{main talk other}} <!-- Don't remove this line. It is supposed to render nothing. But leave it so we see if it fails. -->
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|technical details section]] below.
<pre>
{{main talk other
| 1 = ''This messagebox should not be used in articles.''
| 2 = {{tmbox|text=Talk page notice}}
| 3 = {{ombox|text=Other pages notice}}
}}
</pre>
Which renders like this:
{{main talk other
| 1 = ''This messagebox should not be used in articles.''
| 2 = {{tmbox|text=Talk page notice}}
| 3 = {{ombox|text=Other pages notice}}
}}
Let's see how it looks on talk pages. So we change the first line in the code to this:
<pre>
{{main talk other|demospace=talk
</pre>
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:
<pre>
{{main talk other|demospace=main
</pre>
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 =====
To make this example complete, here is the rest of the code that is needed to make it a fully equipped template:
<pre>
{{main talk other
| demospace = {{{demospace|}}}
| 1 =
| 2 =
| 3 =
}}<noinclude>
{{documentation}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
</pre>
The line "<code><nowiki>| demospace = {{{demospace|}}}</nowiki></code>" 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.
The "<code><nowiki>{{documentation}}</nowiki></code>" template creates a green [[Wikipedia:Template documentation|documentation]] box, like the one you are reading in right now.
=== Technical details ===
===== Numbered parameters and HTML tables =====
Templates have a problem to handle parameter data that contains equal signs "<code>=</code>". But that is easily solved by using numbered parameters, such as "<code>1=First parameter</code>" and "<code>2=Second parameter</code>".
[[Help:Template|Templates]] also do have a problem to handle parameter data that contains pipes "<code>|</code>", unless the pipe is inside another template <code><nowiki>{{name|param1}}</nowiki></code> or inside a piped link <code><nowiki>[[Help:Template|help]]</nowiki></code>. Thus templates can not handle [[Help:Table|wikitables]] as input unless you escape them by using the {{tn|!}} template. This makes it hard to use wikitables as parameters to templates. Instead the usual solution is to use "[[Help:HTML in wikitext|HTML wikimarkup]]" for the table code, which is more robust.
The simplest way to include tables that use wikimarkup is to transclude them as a subtemplate.
===== Comparison =====
{{tl|main talk other}} and {{tl|main talk other flex}} behaves exactly the same but internally uses different code:
* {{tld|main talk other}} will still correctly detect all talk pages even if new namespaces are added to Wikipedia. The talk page and main space detection functions are also shorter and thus nicer if you want to copy them to use them elsewhere:
::{{nowrap|<code><nowiki>{{#ifeq:{{NAMESPACE}}|{{TALKSPACE}}| talk | not talk }}</nowiki></code>}}
::{{nowrap|<code><nowiki>{{#ifeq:{{NAMESPACE}}|{{ns:0}}| main | not main }}</nowiki></code>}}
* {{tld|main talk other flex}} is more flexible in that its code is much easier to modify to detect any combination of namespaces as one wishes. But ''please'' copy the code to a new template before you do such modifications.
* If a new namespace is added to Wikipedia then {{tld|main talk other flex}} needs to be manually updated, otherwise it will detect the new talk space as type "other". Fortunately new namespaces is a very rare event.
So if you just need to detect '''main''', '''talk''' and '''other''' then use {{tld|main talk other}}. But if you want to detect other combinations then copy the code from {{tld|main talk other flex}}.
===== Copying to other projects? =====
<!--This section title is linked to from meta:Help:Namespace-->
If you copy these templates to another language Wikipedia or other Wikimedia project, then {{tld|main talk other}} should work as is, but you probably want to update the template's name and its parameter names to your local namespace naming. But you must update the code of {{tld|main talk category other}} and {{tld|main talk other flex}} to your local naming and add any extra namespaces that are local to your wiki, otherwise they will malfunction.
=== 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 colours and borders. See example on the [[Template talk:Main talk other#CSS namespace detection|talk page]].
{{Namespace and pagename-detecting templates}}
<includeonly>{{Sandbox other||
<!-- ADD CATEGORIES BELOW THIS LINE, PLEASE: -->
[[Category:Namespace manipulation templates]]
}}</includeonly>
<!-- PLEASE ADD CATEGORIES WHERE INDICATED AT THE BOTTOM OF THIS PAGE -->
This is the {{tl|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 [[Wikipedia:Namespace#Enumeration|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.
This page is also the documentation for some other templates:
* {{tl|main talk other flex}} – It works exactly the same, but it has some minor internal differences. Read more about that [[#Technical details|below]].
* {{tl|main other}}, {{tl|talk other}}, {{tl|file other}} and {{tl|category other}} – Simpler versions that only differentiate between one type of page and all other.
== Basic usage ==
This template usually takes three parameters, and returns one of them depending on which type a page belongs to. Like this:
:{{tlc|main talk other|Article text|Talk page text|Other pages text}}
If the template is on a main space (article) page, it will return this:
:{{main talk other|demospace=main|Article text|Talk page text|Other pages text}}
If the template is on any talk page, it will return this:
:{{main talk other|demospace=talk|Article text|Talk page text|Other pages text}}
If the template is on any other page (such as this template page and its doc page), it will return this:
:{{main talk other|Article text|Talk page text|Other pages text}}
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:
:{{tlc|main talk other||Talk text}}
:{{tlc|main talk other||Talk text|}}
Then it doesn't render anything in mainspace and other space.
:{{main talk other||Talk text|}} <!-- Don't remove this line. It is supposed to render nothing. But leave it so we see if it fails. -->
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.
:{{main talk other}} <!-- Don't remove this line. It is supposed to render nothing. But leave it so we see if it fails. -->
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|technical details section]] below.
<pre>
{{main talk other
| 1 = ''This messagebox should not be used in articles.''
| 2 = {{tmbox|text=Talk page notice}}
| 3 = {{ombox|text=Other pages notice}}
}}
</pre>
Which renders like this:
{{main talk other
| 1 = ''This messagebox should not be used in articles.''
| 2 = {{tmbox|text=Talk page notice}}
| 3 = {{ombox|text=Other pages notice}}
}}
Let's see how it looks on talk pages. So we change the first line in the code to this:
<pre>
{{main talk other|demospace=talk
</pre>
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:
<pre>
{{main talk other|demospace=main
</pre>
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 =====
To make this example complete, here is the rest of the code that is needed to make it a fully equipped template:
<pre>
{{main talk other
| demospace = {{{demospace|}}}
| 1 =
| 2 =
| 3 =
}}<noinclude>
{{documentation}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
</pre>
The line "<code><nowiki>| demospace = {{{demospace|}}}</nowiki></code>" 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.
The "<code><nowiki>{{documentation}}</nowiki></code>" template creates a green [[Wikipedia:Template documentation|documentation]] box, like the one you are reading in right now.
=== Technical details ===
===== Numbered parameters and HTML tables =====
Templates have a problem to handle parameter data that contains equal signs "<code>=</code>". But that is easily solved by using numbered parameters, such as "<code>1=First parameter</code>" and "<code>2=Second parameter</code>".
[[Help:Template|Templates]] also do have a problem to handle parameter data that contains pipes "<code>|</code>", unless the pipe is inside another template <code><nowiki>{{name|param1}}</nowiki></code> or inside a piped link <code><nowiki>[[Help:Template|help]]</nowiki></code>. Thus templates can not handle [[Help:Table|wikitables]] as input unless you escape them by using the {{tn|!}} template. This makes it hard to use wikitables as parameters to templates. Instead the usual solution is to use "[[Help:HTML in wikitext|HTML wikimarkup]]" for the table code, which is more robust.
The simplest way to include tables that use wikimarkup is to transclude them as a subtemplate.
===== Comparison =====
{{tl|main talk other}} and {{tl|main talk other flex}} behaves exactly the same but internally uses different code:
* {{tld|main talk other}} will still correctly detect all talk pages even if new namespaces are added to Wikipedia. The talk page and main space detection functions are also shorter and thus nicer if you want to copy them to use them elsewhere:
::{{nowrap|<code><nowiki>{{#ifeq:{{NAMESPACE}}|{{TALKSPACE}}| talk | not talk }}</nowiki></code>}}
::{{nowrap|<code><nowiki>{{#ifeq:{{NAMESPACE}}|{{ns:0}}| main | not main }}</nowiki></code>}}
* {{tld|main talk other flex}} is more flexible in that its code is much easier to modify to detect any combination of namespaces as one wishes. But ''please'' copy the code to a new template before you do such modifications.
* If a new namespace is added to Wikipedia then {{tld|main talk other flex}} needs to be manually updated, otherwise it will detect the new talk space as type "other". Fortunately new namespaces is a very rare event.
So if you just need to detect '''main''', '''talk''' and '''other''' then use {{tld|main talk other}}. But if you want to detect other combinations then copy the code from {{tld|main talk other flex}}.
===== Copying to other projects? =====
<!--This section title is linked to from meta:Help:Namespace-->
If you copy these templates to another language Wikipedia or other Wikimedia project, then {{tld|main talk other}} should work as is, but you probably want to update the template's name and its parameter names to your local namespace naming. But you must update the code of {{tld|main talk category other}} and {{tld|main talk other flex}} to your local naming and add any extra namespaces that are local to your wiki, otherwise they will malfunction.
=== 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 colours and borders. See example on the [[Template talk:Main talk other#CSS namespace detection|talk page]].
{{Namespace and pagename-detecting templates}}
<includeonly>{{Sandbox other||
<!-- ADD CATEGORIES BELOW THIS LINE, PLEASE: -->
[[Category:Namespace manipulation templates]]
}}</includeonly>