Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Usage  



1.1  Handling equals-signs ("=")  





1.2  page parameter  







2 Technical note  





3 Alternatives for simpler text  





4 See also  














Template:When on basepage






ak:Nhwɛsode:Basepage subpage
العربية

تۆرکجه

 / Bân-lâm-gú

Bosanski
ChiTumbuka
Corsu
Cymraeg
Dansk
Ελληνικά
فارسی
Føroyskt

  / Gõychi Konknni
Gungbe

ि
Ilokano
Bahasa Indonesia
IsiZulu
Jawa
Kurdî
Latina
ि
Македонски


مصرى
Bahasa Melayu
 / Mìng-dĕ̤ng-nḡ
Монгол


Norfuk / Pitkern
ି
Oʻzbekcha / ўзбекча
Português
Qaraqalpaqsha
Română
Русский

Scots
Simple English
Slovenščina
کوردی
Српски / srpski
ி
Taqbaylit
 


Тоҷикӣ

Türkçe
Українська
اردو
Tiếng Vit

Yorùbá


 

Edit links
 









Template
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 




In other projects  



Wikimedia Commons
Meta-Wiki
Wikimedia Outreach
Wikispecies
Wikibooks
Wikidata
Wikiquote
Wikiversity
 
















Appearance
   

 





Permanently protected template

From Wikipedia, the free encyclopedia
 

(Redirected from Template:Basepage subpage)

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.

Ifpage 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


Retrieved from "https://en.wikipedia.org/w/index.php?title=Template:When_on_basepage&oldid=627655680"

Categories: 
Pagename manipulation templates
Wikipedia metatemplates
Hidden categories: 
Wikipedia template-protected templates
Navboxes using background colours
 



This page was last edited on 30 September 2014, at 08:52 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki