Template:When on basepage/doc: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Davidgothberg
Adding a caution that I might change the syntax for the demospace parameter. And adding some "See also" links.
meta>Davidgothberg
Changing section "Demospace" to "Page" since the template now uses the "page" parameter instead.
Line 1: Line 1:
{{documentation subpage}}
{{documentation subpage}}
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
{{caution
| This template is new. It is tested and works well. But I am thinking of changing how the '''demospace''' parameter works. However, the functionality of parameters 1-3 will not be changed. <br> --[[User:Davidgothberg|David Göthberg]] ([[User talk:Davidgothberg|talk]]) 01:18, 4 November 2009 (UTC)
}}


This is the {{tl|basepage subpage}} meta-template.
This is the {{tl|basepage subpage}} meta-template.
Line 74: Line 70:
}}
}}


=== Demospace ===
=== Page ===


For testing and demonstration purposes this template can take a parameter named '''demospace'''.
For testing and demonstration purposes this template can take a parameter named '''page'''. Like this:
 
* If it has the value '''basepage''' it returns the basepage text.
* It if has the value '''subpage''' it returns the subpage text.
* It if has the value '''subsubpage''' it returns the subsubpage text if there is one, otherwise it returns the subpage text.
* If the parameter is empty or undefined, the actual page type determines the result.
 
Like this:


<pre>
<pre>
Line 89: Line 78:
| Basepage text
| Basepage text
| Subpage text
| Subpage text
| demospace = subpage
| page = User:Example/test
}}
}}
</pre>
</pre>
Line 98: Line 87:
| Basepage text
| Basepage text
| Subpage text
| Subpage text
| demospace = subpage
| page = User:Example/test
}}
}}


You can make it so your template also understands the '''demospace''' parameter. That means you can demonstrate the different appearances of your template in the documentation for your template. Then do like 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:


<pre>
<pre>
Line 107: Line 102:
| Basepage text
| Basepage text
| Subpage text
| Subpage text
| demospace = {{{demospace|}}}
| page = {{{page|}}}
}}
}}
</pre>
</pre>
Line 120: Line 115:
| 2 = Subpage text
| 2 = Subpage text
| 3 = Subsubpage text
| 3 = Subsubpage text
| demospace = {{{demospace|}}}
| page = {{{page|}}}
}}
}}
</pre>
</pre>

Revision as of 12:16, 4 November 2009

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 will return this:

Subpage 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:

Subpage 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

Page

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.

See also