Template:Basepage subpage
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
Basepage subpage
No description.
Parameter | Description | Type | Status | |
---|---|---|---|---|
page | page | no description | Unknown | optional |
{{Sandbox other||
The above documentation is transcluded from Template:Basepage subpage/doc (edit | history). Editors can experiment in this template's sandbox (edit | diff) and testcases (create) page. Please add categories to the /doc subpage. Subpages of this template. |