Jump to content

Template:Basepage subpage

Page permanently protected
From Wikidata
Documentation icon Template documentation[view · edit · history · purge ]

The {{Basepage subpage}} meta-template helps other templates to detect if they have been transcluded on a basepage, subpage or sub-subpage.

Usage

This template takes one or more parameters of the form:

{{Basepage subpage
 | Basepage text
 | Subpage text
}}

If the template is transcluded on the page "User:Example", it could be implemented as:

Basepage text

If the template was transcluded on "User:Example/test" or "User:Example/test/test", though, or any of their subpages, it will return this:

Subpage text

This template can also detect "sub-subpages", like this:

{{Basepage subpage
 | Basepage text
 | Subpage text
 | Subsubpage text
}}

If the template was transcluded on "User:Example/test/test" or any deeper subpage of it, it will return:

Subsubpage text

By using an empty parameter, you can keep the template from outputting anything for those specific page type(s), like this:

{{Basepage subpage
 | Basepage text
 | Subpage text
 | 
}}

The code above will render nothing when transcluded on "User:Example/test/test" or deeper, but will return this when on "User:Example/test":

Subpage text

The "page" parameter

For testing and demonstration purposes, this template will accept a value from the |page= parameter, Like this:

{{Basepage subpage
 | Basepage text
 | Subpage text
 | page = User:Example/test
}}

No matter what kind of page the above wikitext is placed on, it will then return:

Subpage text

The |page= parameter makes this template behave exactly as if it were being parsed on that page. Thus, if a sub-subpage like "User:Example/test/test" is defined, then it returns the sub-subpage text if there is any, otherwise it will return the subpage text.

The value of the |page= does not need to be an existing page, either.

If the parameter is empty or undefined, the name of the page it is being parsed on determines the output.

You can make it so that your template also understands the |page= parameter. That means you can demonstrate the different appearances of your template in the documentation for your template. Then do like this:

{{Basepage subpage
 | Basepage text
 | Subpage text
 | page = {{{page|}}}
}}

Technical details

Templates have a problem to handle parameter data that contains equality symbols (=), but that is easily solved by using explicit named parameters, or replacing the offending character in the parameter value with its corresponding named HTML entity form. For example:

{{Basepage subpage
 | 1 = Basepage text
 | 2 = Subpage text
 | 3 = Subsubpage text
 | page = {{{page|}}}
}}

This template detects subpages even when used in namespaces that don't have the MediaWiki subpage feature enabled, thus this template works the same in all namespaces.

TemplateData

This is the TemplateData documentation for this template used by VisualEditor and other tools.

Basepage subpage

No description.

Template parameters[Edit template data]

This template prefers block formatting of parameters.

ParameterDescriptionTypeStatus
pagepage

no description

Unknownoptional

{{Sandbox other||