Template:When on basepage/doc: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Sardanaphalus
updates following move
Ookami (talk | contribs)
m 37 revisions imported
 
(7 intermediate revisions by 6 users not shown)
Line 4: Line 4:
This is the {{tl|When on basepage}} meta-template. It helps other templates detect if they are on a '''basepage''' (i.e. a page whose name matches the pattern "''x'':''x''") '''subpage''' ("''x'':''x''/''x''") or '''subsubpage''' ("''x'':''x''/''x''/''x''").
This is the {{tl|When on basepage}} meta-template. It helps other templates detect if they are on a '''basepage''' (i.e. a page whose name matches the pattern "''x'':''x''") '''subpage''' ("''x'':''x''/''x''") or '''subsubpage''' ("''x'':''x''/''x''/''x''").


An alternative way to detect whether a page is a subpage is to combine the parser functions {{plaincode|#ifeq:}} and {{plaincode|#titleparts}}. See [[#Alternatives for simpler text|Alternatives for simpler text]] below.
An alternative way to detect whether a page is a subpage is to combine the parser functions <code>#ifeq:</code> and <code>#titleparts</code>. See [[#Alternatives for simpler text|Alternatives for simpler text]] below.


== Usage ==
== Usage ==
Line 10: Line 10:
: {{tlx|When on basepage&#32;|''result if on a basepage''&#32;(|''result if on a subpage'')&#32;(|''result if on a subsubpage'')&#32;(|page{{=}}''pagename'')}}
: {{tlx|When on basepage&#32;|''result if on a basepage''&#32;(|''result if on a subpage'')&#32;(|''result if on a subsubpage'')&#32;(|page{{=}}''pagename'')}}


For example, {{tcpl|When on basepage |Basepage |Subpage}} on the page "User:Example" would return: {{When on basepage|Basepage|Subpage|page=User:Example}}<br/>whilst on "User:Example/page" (or "User:Example/page/page", "User:Example/page/page/page", etc) it would return: {{When on basepage|Basepage|Subpage|page=User:Example/page}}
For example, {{tlf|When on basepage |Basepage |Subpage}} on the page "User:Example" would return: {{When on basepage|Basepage|Subpage|page=User:Example}}<br/>whilst on "User:Example/page" (or "User:Example/page/page", "User:Example/page/page/page", etc.) it would return: {{When on basepage|Basepage|Subpage|page=User:Example/page}}


On a subsubpage such as "User:Example/page/page" (or "User:Example/page/page/page", etc), {{nowrap|{{tcpl|When on basepage |Basepage |Subpage |Subsubpage}}}} would return: {{When on basepage |Basepage |Subpage |Subsubpage |page=User:Example/page/page}}
On a subsubpage such as "User:Example/page/page" (or "User:Example/page/page/page", etc.), {{nowrap|{{tlf|When on basepage |Basepage |Subpage |Subsubpage}}}} would return: {{When on basepage |Basepage |Subpage |Subsubpage |page=User:Example/page/page}}


Use an empty parameter to specify no action for a particular type of page. {{nowrap|{{tcpl|When on basepage |Basepage | |Subsubpage}}}} on "User:Example/page", for example, would return nothing, but would return "Subsubpage" if on "User:Example/page/page", "User:Example/page/page/page", etc (and "Basepage" if on "User:Example").
Use an empty parameter to specify no action for a particular type of page. {{nowrap|{{tlf|When on basepage |Basepage | |Subsubpage}}}} on "User:Example/page", for example, would return nothing, but would return "Subsubpage" if on "User:Example/page/page", "User:Example/page/page/page", etc. (and "Basepage" if on "User:Example").


===Handling equals-signs ("=")===
===Handling equals-signs ("=")===
Use numbered parameters if their values include equals-signs ("="), i.e.
Use numbered parameters if their values include equals-signs ("="), i.e.
: {{tcpl|When on basepage&#32;|1{{=}}''basepage result'' (|2{{=}}''subpage result'') (|3{{=}}''subsubpage result'')}}
: {{tlf|When on basepage&#32;|1{{=}}''basepage result'' (|2{{=}}''subpage result'') (|3{{=}}''subsubpage result'')}}


===''page'' parameter===
===''page'' parameter===
The ''page'' parameter is included for testing/demonstration. For example:
The ''page'' parameter is included for testing/demonstration. For example:
: {{tcpl|When on basepage&#32;|(basepage result) |(subpage result) |page{{=}}User:Example/test}}
: {{tlf|When on basepage&#32;|(basepage result) |(subpage result) |page{{=}}User:Example/test}}
Regardless of where the above is placed, it will return: {{When on basepage|(basepage result)|(subpage result)|page=User:Example/test}}<br/>(because "User:Example/test" is a subpage). The page doesn't have to exist.
Regardless of where the above is placed, it will return: {{When on basepage|(basepage result)|(subpage result)|page=User:Example/test}}<br/>(because "User:Example/test" is a subpage). The page doesn't have to exist.


If ''page'' is left empty ({{para|page}}) or undefined, the page where the template is transcluded (i.e. {{wikivar|PAGENAME}}) is used.
If ''page'' is left empty ({{para|page}}) or undefined, the page where the template is transcluded (i.e. {{tld|PAGENAME}}) is used.


''page'' also accepts variables, e.g. {{nowrap|{{tcpl|When on basepage |(basepage result) |(subpage result) |page<nowiki>={{{page|}}}</nowiki>&nbsp;}}}}
''page'' also accepts variables, e.g. {{nowrap|{{tlf|When on basepage |(basepage result) |(subpage result) |page<nowiki>={{{page|}}}</nowiki>&nbsp;}}}}


== Technical note ==
== Technical note ==
Line 35: Line 35:
== Alternatives for simpler text ==
== Alternatives for simpler text ==


A subpage can be detected without using another template, by instead using the title-splitting parser function {{plaincode|#titleparts}} with {{plaincode|#ifeq}}:
A subpage can be detected without using another template, by instead using the title-splitting parser function <code>#titleparts</code> with <code>#ifeq</code>:
<pre>
<pre>
{{#ifeq:{{#titleparts:{{PAGENAME}}|1|1}}|{{PAGENAME}}
{{#ifeq:{{#titleparts:{{PAGENAME}}|1|1}}|{{PAGENAME}}
Line 47: Line 47:
:: <nowiki> | {{template sandbox notice}}</nowiki>
:: <nowiki> | {{template sandbox notice}}</nowiki>
: <nowiki>}}</nowiki>
: <nowiki>}}</nowiki>
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 <code>#ifeq</code>, then the processing uses only +2 expansion depth levels, rather than +7 levels, and avoids "[[wp:exceeded template limits]]" inside a complex /doc page.
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 <code>#ifeq</code>, then the processing uses only +2 expansion depth levels, rather than +7 levels, and avoids "[[wp:exceeded template limits]]" inside a complex /doc page.


== See also ==
== See also ==
{{Pagename detect see also}}
{{Namespace and pagename-detecting templates}}


<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox |
<includeonly>{{Sandbox other||
| <!--Categories below this line, please; interwikis at Wikidata-->
<!--Categories below this line, please; interwikis at Wikidata-->
[[Category:Namespace manipulation templates]]
[[Category:Pagename manipulation templates]]
[[Category:Wikipedia metatemplates]]
[[Category:Wikipedia metatemplates]]
}}</includeonly>
}}</includeonly>

Latest revision as of 14:11, 3 September 2020

This is the {{When on basepage}} meta-template. It helps other templates detect if they are on a basepage (i.e. a page whose name matches the pattern "x:x") subpage ("x:x/x") or subsubpage ("x:x/x/x").

An alternative way to detect whether a page is a subpage is to combine the parser functions #ifeq: and #titleparts. See Alternatives for simpler text below.

Usage

{{When on basepage |result if on a basepage (|result if on a subpage) (|result if on a subsubpage) (|page=pagename)}}

For example, {{When on basepage|Basepage|Subpage}} on the page "User:Example" would return: Basepage
whilst on "User:Example/page" (or "User:Example/page/page", "User:Example/page/page/page", etc.) it would return: Subpage

On a subsubpage such as "User:Example/page/page" (or "User:Example/page/page/page", etc.), {{When on basepage|Basepage|Subpage|Subsubpage}} would return: Subsubpage

Use an empty parameter to specify no action for a particular type of page. {{When on basepage|Basepage|Subsubpage}} on "User:Example/page", for example, would return nothing, but would return "Subsubpage" if on "User:Example/page/page", "User:Example/page/page/page", etc. (and "Basepage" if on "User:Example").

Handling equals-signs ("=")

Use numbered parameters if their values include equals-signs ("="), i.e.

{{When on basepage |1=basepage result (|2=subpage result) (|3=subsubpage result)}}

page parameter

The page parameter is included for testing/demonstration. For example:

{{When on basepage |(basepage result)|(subpage result)|page=User:Example/test}}

Regardless of where the above is placed, it will return: (subpage result)
(because "User:Example/test" is a subpage). The page doesn't have to exist.

If page is left empty (|page=) or undefined, the page where the template is transcluded (i.e. {{PAGENAME}}) is used.

page also accepts variables, e.g. {{When on basepage|(basepage result)|(subpage result)|page={{{page|}}} }}

Technical note

This template detects subpages in all namespaces, including those without the MediaWiki subpage feature enabled.

Alternatives for simpler text

A subpage can be detected without using another template, by instead using the title-splitting parser function #titleparts with #ifeq:

{{#ifeq:{{#titleparts:{{PAGENAME}}|1|1}}|{{PAGENAME}}
 | [...code if on a basepage...]
 | [...code if on a subpage...]
}}

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

{{#ifeq: {{#titleparts:{{PAGENAME}}|1|1}} | {{PAGENAME}}
| {{documentation}}
| {{template sandbox notice}}
}}

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 #ifeq, then the processing uses only +2 expansion depth levels, rather than +7 levels, and avoids "wp:exceeded template limits" inside a complex /doc page.

See also