User:Gorgon/Sandbox/Sandbox Charlie
Template:Ns detect (Namespace detect)
This template is based on Template:Namespace detect.
It uses the original markup, modified for Avlis wiki namespaces. The documentation below was copied to this template, since we do not use documentation sub-pages. It has also been modified for Avlis namespaces, and most of the MediaWiki specific information, links and sub-templates have either been removed, or modified for the Avlis wiki. It has been reformatted, and several sections modified for improved clarity.
See the original template documentation for further details.
Template documentation
This is the {{ns detect}} (Namespace detect) meta-template.
It helps other templates detect what type of namespace they are used in.
It detects and groups all of the different namespaces used on the Avlis wiki into several types:
- main = Main/article namespace, as in normal Avlis wiki articles.
- talk = Any talk namespace, such as page names that start with "Talk:", "User talk:", "File talk:" and so on.
- user, avlis wiki, file, mediawiki, template, help, and category = The other namespaces, except for talk namespace pages.
- other = Any namespaces that were not specified as a parameter to the template. See the Note: in the " Parameters" section below.
For backwards compatibility, this template also understands the old name image for file. But using image is now deprecated.
Usage
Note: The following examples use multiple lines for improved readability. All of them can be written as single lines as well.
E.g., {{ns detect | main = Article text | talk = Talk page text | other = Other pages text}}
for the first example below.
This template takes one or more parameters, named after the different namespaces listed above. Like this:
{{ns detect | main = Article text | talk = Talk page text | other = Other pages text }}
If the template is in a main (article) namespace page, it will return this:
- Article text
If the template is used in any other namespace page than a main (article), or a talk page, it will return this:
- Other pages text
The example above made the template return something for all other namespace page types. But if we don't use the other parameter, or leave it empty, then it will not return anything for the other namespace page types. Like this:
{{ns detect | file = File page text | category = Category page text | other = }}
In any pages, other than file and category namespace pages, the code above will render nothing.
By using an empty parameter, you can make it so the template doesn't render anything for a specific namespace page type. Like this:
{{ns detect | main = | other = Other pages text }}
The code above will render nothing when in main (article) namespace pages, but will return this when in other namespace pages:
- Other pages text
Demospace and page
For testing and demonstration purposes, this template can take two parameters, named demospace and page.
Demospace understands any of the namespace page type names used by this template, including the other namespace type. It tells the template to behave like it is in a specific type of namespace page. Like this:
{{ns detect | main = Article text | other = Other pages text | demospace = main }}
No matter what kind of namespace page the code above is used in, it will return this:
- Article text
The page parameter instead takes a normal {{PAGENAME}} (Full page title, including all subpage levels, without the namespace). It makes this template behave exactly as if rendered on that page. The pagename doesn't have to be an existing page. Like this:
{{ns detect | user = User page text | other = Other pages text | page = User:Example }}
No matter what kind of namespace page the code above is used in, it will return this:
- User page text
It may be convenient to define the demospace and/or page parameters in your template, and send them on to the {{ns detect}} template. Then do like this:
{{ns detect | main = Article text | other = Other pages text | demospace = {{{demospace|}}} | page = {{{page|}}} }}
If both the demospace and page parameters are empty, or undefined, then the template will detect namespace page types as usual.
Parameters
List of all parameters:
{{ns detect | main = | talk = | user = | avlis wiki = | file = | mediawiki = | template = | help = | category = | other = | demospace = {{{demospace|}}} One of: main, talk, user, avlis wiki, file, mediawiki, template, help, category, other | page = {{{page|}}} E.g., User:Example }}
Note: Empty values for the main through category parameters are different than not including (defining) them. An undefined parameter (i.e, one you do not include in your template usage) will use the result of the other parameter when in that namespace. Any that are defined, but not assigned a value (i.e, included in the template usage, but nothing after the = ) will render nothing when used in that namespace.
Technical details
If you intend to use wikitables as parameter values in this template, then you need to know this:
Templates have a problem handling parameter data that contains pipes "|
", unless the pipe is inside another template {{name|param1}}
, or inside a piped link [[Help:Template|help]]
. Therefore templates can not handle wikitables as input, unless you escape them by using the {{!}} magic word (parser function - see: Help:Magic words#Other). This makes it hard to use wikitables as parameters in templates. Instead, the usual solution is to use HTML wikimarkup for the table code, which is more robust.
Note: Template:! functionality was replaced in MediaWiki version 1.24 by the {{!}} magic word, and is ignored when using it.