Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Template:Basepage subpage/doc: Difference between revisions

Template page
No edit summary
m syntaxhighlight lang="wikitext"
 
Line 9: Line 9:


This template takes one or more parameters, like this:
This template takes one or more parameters, like this:
<pre>
<syntaxhighlight lang="wikitext">
{{basepage subpage
{{basepage subpage
| Basepage text
| Basepage text
| Subpage text
| Subpage text
}}
}}
</pre>
</syntaxhighlight>


If the template is on the page "User:Example", it shall return this:
If the template is on the page "User:Example", it shall return this:
Line 34: Line 34:
This template can also detect "subsubpages", like this:
This template can also detect "subsubpages", like this:


<pre>
<syntaxhighlight lang="wikitext">
{{basepage subpage
{{basepage subpage
| Basepage text
| Basepage text
Line 40: Line 40:
| Subsubpage text
| Subsubpage text
}}
}}
</pre>
</syntaxhighlight>


If the template is on "User:Example/test/test" or any page lower than that, it will return this:
If the template is on "User:Example/test/test" or any page lower than that, it will return this:
Line 53: Line 53:
By using an empty parameter you can make it so the template doesn't render anything for some specific page type. Like this:
By using an empty parameter you can make it so the template doesn't render anything for some specific page type. Like this:


<pre>
<syntaxhighlight lang="wikitext">
{{basepage subpage
{{basepage subpage
| Basepage text
| Basepage text
Line 59: Line 59:
|  
|  
}}
}}
</pre>
</syntaxhighlight>


The code above will render nothing when on "User:Example/test/test" or lower, but will return this when on "User:Example/test":
The code above will render nothing when on "User:Example/test/test" or lower, but will return this when on "User:Example/test":
Line 74: Line 74:
For testing and demonstration purposes this template can take a parameter named '''page'''. Like this:
For testing and demonstration purposes this template can take a parameter named '''page'''. Like this:


<pre>
<syntaxhighlight lang="wikitext">
{{basepage subpage
{{basepage subpage
| Basepage text
| Basepage text
Line 80: Line 80:
| page = User:Example/test
| page = User:Example/test
}}
}}
</pre>
</syntaxhighlight>


No matter on what kind of page the code above is used it will return this:
No matter on what kind of page the code above is used it will return this:
Line 98: Line 98:
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:
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:


<pre>
<syntaxhighlight lang="wikitext">
{{basepage subpage
{{basepage subpage
| Basepage text
| Basepage text
Line 104: Line 104:
| page = {{{page|}}}
| page = {{{page|}}}
}}
}}
</pre>
</syntaxhighlight>


=== Technical details ===
=== Technical details ===
Line 110: Line 110:
Templates have a problem to handle parameter data that contains equal signs "<code>=</code>". But that is easily solved by using numbered parameters. Like this:
Templates have a problem to handle parameter data that contains equal signs "<code>=</code>". But that is easily solved by using numbered parameters. Like this:


<pre>
<syntaxhighlight lang="wikitext">
{{basepage subpage
{{basepage subpage
| 1 = Basepage text
| 1 = Basepage text
Line 117: Line 117:
| page = {{{page|}}}
| page = {{{page|}}}
}}
}}
</pre>
</syntaxhighlight>


This template detects subpages even when used in namespaces that doesn't have the MediaWiki [[meta:Link#Subpage feature|subpage feature]] enabled. Thus this template works the same in all namespaces.
This template detects subpages even when used in namespaces that doesn't have the MediaWiki [[meta:Link#Subpage feature|subpage feature]] enabled. Thus this template works the same in all namespaces.

Latest revision as of 19:47, 8 June 2023

This is the {{Basepage subpage}} meta-template.

This template helps other templates detect if they are on a basepage, subpage or subsubpage.

Usage

This template takes one or more parameters, like this:

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

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

Basepage text

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

Subpage text

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

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

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

Subsubpage text

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

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

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

Subpage text

The "page" parameter

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

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

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

Subpage text

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:

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

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:

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

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.

Cookies help us deliver our services. By using our services, you agree to our use of cookies.