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

From blackwiki
Jump to navigation Jump to search
test>Davidgothberg
(Added "Category:Wikipedia metatemplates".)
m (21 revisions imported)
 
(17 intermediate revisions by 6 users not shown)
Line 4: Line 4:
 
This is the {{tl|main talk other flex}} template.
 
This is the {{tl|main talk other flex}} template.
  
This template detects and returns what namespace group a page belongs to. Depending on what kind of page it is used on it returns one of these three lower case words:
+
It helps other templates detect what type of page they are on.
:'''main''' = Main/article space, as in normal Wikipedia articles.
 
:'''talk''' = Any talk space, such as page names that start with "Talk:", "User talk:", "Image talk:" and so on.
 
:'''other''' = All other spaces, such as page names that start with "User:", "Image:", "Wikipedia:" and so on.
 
  
This template page (and its doc page) belongs in the namespace group "other". Thus:
+
Documentation for all these templates are at {{tl|main talk other}}.  
  
<pre>
+
This template works exactly the same as the {{tlf|main talk other}} template, but it has some minor internal differences. The documentation at {{tlf|main talk other}} covers some of the differences, the rest are explained below.
{{main talk other flex}}
 
</pre>
 
  
Renders like this:
+
'''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.
  
:{{main talk other flex}}
+
=== About the code ===
  
This template can also take three parameters and then returns (uses) one of them depending on which namespace group a page belongs to. Like this:
+
The line "<code><nowiki>| {{lc:{{ns:0}}}} = </nowiki></code>" probably needs some explanation. Currently mainspace (article space) doesn't have a name, so for mainspace the magic word <nowiki>{{NAMESPACE}}</nowiki> returns an empty string. Fortunately MediaWiki switch-cases can handle empty strings. So that line could simply be "<code><nowiki>| = </nowiki></code>". But just in case the mainspace ever gets a name we use the "<code><nowiki>{{ns:0}}</nowiki></code>" 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 "<code><nowiki>{{lc:}}</nowiki></code>". 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.
  
<pre>
+
{{Namespace and pagename-detecting templates}}
{{main talk other flex|Article text|Talk page text|Other pages text}}
 
</pre>
 
  
Which renders like this:
+
<includeonly>{{Sandbox other||
 
 
:{{main talk other flex|Article text|Talk page text|Other pages text}}
 
 
 
 
 
=== More docs soon ===
 
 
 
The template code itself is ready and tested. But these docs will be extended a lot within some days.
 
 
 
--[[User:Davidgothberg|David Göthberg]] ([[User talk:Davidgothberg|talk]]) 20:28, 15 March 2008 (UTC)
 
 
 
=== Links for this code ===
 
 
 
* [[Wikipedia:Namespace]]
 
* [[Help:Magic words]]
 
* [[meta:Help:ParserFunctions]]
 
* {{tl|pp-meta}}
 
* {{tl|notice}}
 
 
 
=== See also ===
 
 
 
* {{tl|main talk other}} - Another version of this template.
 
 
 
<includeonly>
 
 
<!-- ADD CATEGORIES AND INTERWIKIS BELOW THIS LINE -->
 
<!-- ADD CATEGORIES AND INTERWIKIS BELOW THIS LINE -->
[[Category:Wikipedia metatemplates|{{PAGENAME}}]]
+
[[Category:Namespace manipulation templates]]
  
</includeonly>
+
}}</includeonly>

Latest revision as of 16:12, 7 September 2020

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.