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

From blackwiki
Jump to navigation Jump to search
test>Davidgothberg
(More "note!" explanation.)
test>Davidgothberg
(Added: "(We just discovered that switch cases ''can'' handle empty strings...)" I don't want to spread faulty knowledge.)
Line 14: Line 14:
 
=== About the code ===
 
=== About the code ===
  
The lines "<code><nowiki>| x{{NAMESPACE}}</nowiki></code>" and "<code><nowiki>| x =</nowiki></code>" probably needs some explanation. The reason we do like that is because mainspace (articlespace) doesn't have a name, so for mainspace the magic word <nowiki>{{NAMESPACE}}</nowiki> returns an empty string. But switch cases can not handle empty strings. Thus we need to make the string non-empty in some way. The easiest way is to simply add an "x" to it. Thus "x+nothing = x" and namespace then has the name "x" in the switch case. As a side effect all the other namespaces start with an x too.
+
The lines "<code><nowiki>| x{{NAMESPACE}}</nowiki></code>" and "<code><nowiki>| x =</nowiki></code>" probably needs some explanation. The reason we do like that is because mainspace (articlespace) doesn't have a name, so for mainspace the magic word <nowiki>{{NAMESPACE}}</nowiki> returns an empty string. <s>But switch cases can not handle empty strings.</s> Thus we need to make the string non-empty in some way. The easiest way is to simply add an "x" to it. Thus "x+nothing = x" and namespace then has the name "x" in the switch case. As a side effect all the other namespaces start with an x too. (We just discovered that switch cases ''can'' handle empty strings...)
 +
 
  
 
<includeonly>
 
<includeonly>

Revision as of 07:11, 30 March 2008

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 lines "| x{{NAMESPACE}}" and "| x =" probably needs some explanation. The reason we do like that is because mainspace (articlespace) doesn't have a name, so for mainspace the magic word {{NAMESPACE}} returns an empty string. But switch cases can not handle empty strings. Thus we need to make the string non-empty in some way. The easiest way is to simply add an "x" to it. Thus "x+nothing = x" and namespace then has the name "x" in the switch case. As a side effect all the other namespaces start with an x too. (We just discovered that switch cases can handle empty strings...)