Difference between revisions of "Template:Main talk other flex"

From blackwiki
Jump to navigation Jump to search
test>Davidgothberg
(Removing the x:s since MediaWiki can handle empty values in switch cases. Lower casing the ns:0 is not necessary since it is an empty string, but just in case people reuse it for other namespaces.)
test>Davidgothberg
(Removing the "return 'main'/'talk'/'other' when no parameter" function, since not used, not needed and causes problems in some situations.)
Line 1: Line 1:
 
{{#switch:
 
{{#switch:
 
   {{lc:              <!--Lower case the result-->
 
   {{lc:              <!--Lower case the result-->
     <!--If no or empty "demospace" parameter then use x+NAMESPACE-->
+
     <!--If no or empty "demospace" parameter then use NAMESPACE-->
 
     {{#if:{{{demospace|}}}  
 
     {{#if:{{{demospace|}}}  
 
     | {{{demospace}}}
 
     | {{{demospace}}}
Line 7: Line 7:
 
     }}  
 
     }}  
 
   }}
 
   }}
 +
 +
<!-- "demospace=main" or main (article) space -->
 
| main
 
| main
| {{lc:{{ns:0}}}} =   <!--Parameter "main" or main (article) space-->
+
| {{lc:{{ns:0}}}} = {{{1|}}}
 
 
<!--If any parameter, then don't return the "main" string-->
 
{{#if:{{{1|}}}{{{2|}}}{{{3|}}} | {{{1|}}} | main }}
 
  
 +
<!-- "demospace=talk" or any talk space -->
 
| talk
 
| talk
 
| user talk
 
| user talk
Line 21: Line 21:
 
| help talk
 
| help talk
 
| category talk  
 
| category talk  
| portal talk =       <!--Parameter "talk" or any talk space-->
+
| portal talk = {{{2|}}}
 
 
{{#if:{{{1|}}}{{{2|}}}{{{3|}}} | {{{2|}}} | talk }}
 
  
 +
<!-- "demospace=other" or other space -->
 
| other
 
| other
 
| user
 
| user
Line 34: Line 33:
 
| category
 
| category
 
| portal
 
| portal
| #default =         <!--Parameter "other" or other space-->
+
| #default = {{{3|}}}
 
 
{{#if:{{{1|}}}{{{2|}}}{{{3|}}} | {{{3|}}} | other }}
 
  
 
}}<!--End switch--><noinclude>
 
}}<!--End switch--><noinclude>

Revision as of 05:04, 4 July 2008

Template documentation[view] [edit] [history] [purge]

This is the {{main talk other flex}} template.

It helps other templates detect what type of page they are on.

Documentation for all these templates are at {{main talk other}}.

This template works exactly the same as the {{main talk other}} template, but it has some minor internal differences. The documentation at {{main talk other}} covers some of the differences, the rest are explained below.

Note! Do not optimise or cut away any "unnecessary" parts of the code in this template. This code serves as an example to copy and paste from and then modify, when one wants to make other templates that detect more complex namespace combinations. That's why the code contains a full list of the Wikipedia namespaces, even for the "other" case.

About the code

The line "| {{lc:{{ns:0}}}} = " probably needs some explanation. Currently mainspace (article space) doesn't have a name, so for mainspace the magic word {{NAMESPACE}} returns an empty string. Fortunately MediaWiki switch-cases can handle empty strings. So that line could simply be "| = ". But just in case the mainspace ever gets a name we use the "{{ns:0}}" which should give the name of namespace 0, that is mainspace. And since we lower case the input then we also have to lower case the value we compare, thus we add "{{lc:}}". Another reason we use that code is in-case people want to reuse that approach for the other namespaces when they reuse this code elsewhere. It would be especially useful when porting this template to an other language Wikipedia or other Wikimedia project.