Template:Namespace detect/doc

From K6ka's Wiki
Jump to navigation Jump to search

Description[edit]

This metatemplate is used to help other templates detect which namespace they are in.

It detects and groups the different namespaces on K6ka's Wiki into four types:

  • main: The main or article namespace, where the wiki's content articles are kept.
  • talk: Any talk page, including page names that start with "Talk:", "User talk:", "File talk:", etc.
  • user · k6ka's wiki · file · mediawiki · template · help · category (etc.): The remaining namespaces that serve various different purposes.
  • other: Any namespace that isn't specified as a parameter in this template.

Usage[edit]

This template takes one or more parameters named after the different page types as listed above, like this:

{{Namespace detect
 | main  = Article text
 | talk  = Talk page text
 | other = Other pages text
}}

If the template is on an article page (mainspace), it will return this:

Article text

If the template is on any other page than an article or a talk page, it will return this:

Other pages text

The example above made the template return something for all page types; however, if we don't use the other parameter or leave it empty, it will not return anything for the other page types. Like this:

{{Namespace detect
 | file     = File page text
 | category = Category page text
 | other    =
}}

If the template is used on any page outside of the File or Category pages, it will not display anything.

You can use this trick to make the template not render anything for a specific page type, like this:

{{Namespace detect
 | main  = 
 | other = Other pages text
}}

The above won't display anything on mainspace (article) pages, but on all other pages it will display this:

Other pages text

Testing and debugging parameters[edit]

Because of the nature of this template, testing it can be difficult at times. To help with this, this template has two parameters that allows you to easily test to see how the template will behave in other namespaces without actually having to use this template in those namespaces.

The demospace parameter understands any of the page types used in this template, including the other type. It instructs the template to behave as if it were on a specific type of page. For example:

{{Namespace detect
 | main  = Article text
 | other = Other pages text
 | demospace = main
}}

No matter where the template is used, it will always act as if it were in the main namespace, like this:

Article text

The page parameter takes the full name of a page, making this template behave as if it were on that page. The page you specify in question doesn't actually have to exist. For example:

{{Namespace detect
 | user  = User page text
 | other = Other pages text
 | page  = User:Example
}}

Will cause the template to always act as if it were used on User:Example, like this:

User page text

If both demospace and page are used, demospace will take prevalence, and page will be ignored.

{{Namespace detect
 | main  = Article text
 | other = Other pages text
 | demospace = main
 | page  = Template:Namespace detect
}}

Renders as:

Article text

If you want your template to be able to understand the demospace and page parameters, you can do something like this:

{{Namespace detect
 | main  = Article text
 | other = Other pages text
 | demospace = {{{demospace|}}}
 | page  = {{{page|}}}
}}

If both the demospace and page parameters are left blank, the template will detect page types like normal.

Credits[edit]

This template's code was copied from an old version of Wikipedia's Namespace detect template, found here. This template documentation was taken partially from Template:Namespace detect/doc on the English Wikipedia.