Difference between revisions of "Template:Main other"

From UnderlightWiki
Jump to: navigation, search
(missing templates)
 
 
Line 1: Line 1:
{{Documentation subpage}}
{{#switch:
{{used in system}}
  <!--If no or empty "demospace" parameter then detect namespace-->
{{Template shortcut|ns0|mo|ao}}
  {{#if:{{{demospace|}}}  
<!-- PLEASE ADD CATEGORIES AT THE BOTTOM OF THIS PAGE -->
  | {{lc: {{{demospace}}} }}    <!--Use lower case "demospace"-->
  | {{#ifeq:{{NAMESPACE}}|{{ns:0}}
    | main
    | other
    }}  
  }}
| main    = {{{1|}}}
| other
| #default = {{{2|}}}
}}<noinclude>


This is the {{tl|main other}} meta-template.
{{documentation}}
 
<!-- Add categories to the /doc subpage; interwikis go to Wikidata, thank you! -->
This template helps other templates detect if they are on a main space (article) page or some "other" type of page.
</noinclude>
 
===Basic usage===
This template usually takes two parameters, like this:
: {{Tlc|main other&#32;|''result if in mainspace''&#32;|''result if elsewhere''}}
 
If the template is on a main space (article) page, it will return this:
: {{main other |demospace=main |''result if in mainspace'' |''result if elsewhere''}}
 
If the template is on any other page, it will return this:
: {{main other |''result if in mainspace'' |''result if elsewhere''}}
 
A typical usage case could be to make it so that a template only adds a category when on an article. Thus not adding other pages that just show the template. Like this:
: {{Tlc|main other&#32;|<nowiki>[[:Category:Some article maintenance category]]</nowiki>}}
Note that guidelines do not support categorization in templates.
 
Or to warn that a template should not be used on other pages:
: {{Tlc|main other&#32;|&#32;|This template should only be used in articles.}}
 
Note that in the first case above the "other" parameter was not used, and in the second example the "main" parameter was left empty.
 
===Demospace===
For testing and demonstration purposes, this template can take a parameter named '''demospace'''.
* If it has the value '''main''' it returns the article text.
* It if has the value '''other''' or any other value such as the name of some other namespace it returns the other pages text.
* If the parameter is empty or undefined, the actual page type determines the result.
 
Like this:
: {{tlf|main other&#32;|''result if in mainspace''&#32;|''result if elsewhere''&#32;|demospace{{=}}main}}
 
No matter on what kind of page the code above is used, it will return: {{main other |''result if in mainspace'' |''result if elsewhere'' |demospace=main}}
 
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:
: {{tlf|main other&#32;|''result if in mainspace''&#32;|''result if elsewhere''&#32;|<nowiki>demospace={{{demospace|}}}</nowiki>&#32;}}
 
===Technical details===
This template detects article "Talk:" pages as type '''other'''.
 
This template works like {{tl|main talk other}}. For more examples and technical details, see the documentation there.
 
 
<templatedata>
{
"params": {
"1": {
"label": "If mainspace",
"description": "Content if page is located in mainspace (i.e. article space)",
"type": "content"
},
"2": {
"label": "If not mainspace",
"description": "Content if page is not located in mainspace",
"type": "content"
}
}
}
</templatedata>
 
===Redirects===
* {{tl|article only}}
* {{tl|article other}}
 
{{Namespace and pagename-detecting templates}}
 
<includeonly>{{Sandbox other||
[[Category:Namespace manipulation templates]]
[[Category:If-then-else templates]]
}}</includeonly>

Latest revision as of 12:37, 26 October 2022

{{#switch:

 {{#if: 
 | {{{demospace}}}    
 | {{#ifeq:Template|
   | main
   | other
   }} 
 }}

| main = | other | #default = }}

{{#invoke:documentation|main|_content={{ {{#invoke:documentation|contentTitle}}}}}}