Template:Namespace detect/doc

From The Sims Wiki, a collaborative database for The Sims series
This is an old revision of this page, as edited by sims>K6ka at 14:32, 22 June 2017 (Created page with " ==Description== This metatemplate is used to help other templates detect which namespace they are in. It detects and groups the different n..."). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Description

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

It detects and groups the different namespaces on The Sims 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 · wikipedia · 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.

NB: It is probably easier to use templates like {{Checkmns}} and {{Checkfns}} that only check to see if they're in one specific namespace. This template is meant to be a "catch-all" template that supports all namespaces.

Usage

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 pages other than 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

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

This template's code was copied from K6ka's Wiki on ShoutWiki. This template documentation was taken partially from there as well.