Template:Basepage subpage/doc

__NOWYSIWYG__

Description
This is the basepage subpage meta-template.

This template helps other templates detect if they are on a basepage, subpage or subsubpage. However, a subpage can be detected without using another template, by instead using a single  with parser function   (see below: Alternatives for simpler text).

Usage
This template takes one or more parameters, like this:

If the template is on the page "User:Example", it shall return this:



If the template is on "User:Example/test" or "User:Example/test/test" or any page lower than that, it will return this:



This template can also detect "subsubpages", like this:

If the template is on "User:Example/test/test" or any page lower than that, it will return this:



By using an empty parameter you can make it so the template doesn't render anything for some specific page type. Like this:

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



The "page" parameter
For testing and demonstration purposes this template can take a parameter named page. Like this:

No matter on what kind of page the code above is used it will return this:



The page parameter makes this template behave exactly as if on that page. Thus, if a subsubpagename like "User:Example/test/test" is fed, then it returns the subsubpage text if there is one, otherwise it returns the subpage text.

The pagename doesn't have to be an existing page.

If the parameter is empty or undefined, the name of the current page determines the result.

You can make it so 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:

Technical details
Templates have a problem to handle parameter data that contains equal signs " ". But that is easily solved by using numbered parameters. Like this:

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

Alternatives for simpler text
A subpage can be detected without using another template, by instead using a single  along with the title-splitting parser function , with expansion depth +1, as follows:

For example, many templates can check if the page is a /sandbox version, by the similar markup with  and  :

That simple logic works because Template:Template_sandbox_notice also checks the page name for "/sandbox" before displaying the sandbox notice; otherwise, any other subpage would show no extra text. By avoiding a template, and using a single, then the processing uses only +2 expansion depth levels, rather than +7 levels, and avoids "wp:exceeded template limits" inside a complex /doc page.