Template:Namespace: Difference between revisions

From 118Wiki
Jump to navigation Jump to search
(new metatemplate)
 
(replaced "empty" with more flexible "others", doc to reflect the change)
 
Line 1: Line 1:
<includeonly>{{#switch: {{NAMESPACENUMBER:{{{page|{{FULLPAGENAME}}}}}}}
<includeonly>{{#switch: {{NAMESPACENUMBER:{{{page|{{FULLPAGENAME}}}}}}}
   | 0 = {{{main|{{#ifeq: {{{empty|}}}|yes| |article}}}}}
   | 0 = {{{main|{{{others|article}}}}}}
   | 1 = {{{talk|{{#ifeq: {{{empty|}}}|yes| |talk page}}}}}
   | 1 = {{{talk|{{{others|talk page}}}}}}
   | 2 = {{{user|{{#ifeq: {{{empty|}}}|yes| |user page}}}}}
   | 2 = {{{user|{{{others|user page}}}}}}
   | 3 = {{{user talk|{{#ifeq: {{{empty|}}}|yes| |user talk page}}}}}
   | 3 = {{{user talk|{{{others|user talk page}}}}}}
   | 4 = {{{118wiki|{{#ifeq: {{{empty|}}}|yes| |project page}}}}}
   | 4 = {{{118wiki|{{{others|project page}}}}}}
   | 5 = {{{118wiki talk|{{#ifeq: {{{empty|}}}|yes| |project talk page}}}}}
   | 5 = {{{118wiki talk|{{{others|project talk page}}}}}}
   | 6 = {{{file|{{#ifeq: {{{empty|}}}|yes| |file}}}}}
   | 6 = {{{file|{{{others|file}}}}}}
   | 7 = {{{file talk|{{#ifeq: {{{empty|}}}|yes| |file talk page}}}}}
   | 7 = {{{file talk|{{{others|file talk page}}}}}}
   | 8 = {{{mediawiki|{{#ifeq: {{{empty|}}}|yes| |MediaWiki system page}}}}}
   | 8 = {{{mediawiki|{{{others|MediaWiki system page}}}}}}
   | 9 = {{{mediawiki talk|{{#ifeq: {{{empty|}}}|yes| |MediaWiki system talk page}}}}}
   | 9 = {{{mediawiki talk|{{{others|MediaWiki system talk page}}}}}}
   | 10 = {{{template|{{#ifeq: {{{empty|}}}|yes| |template}}}}}
   | 10 = {{{template|{{{others|template}}}}}}
   | 11 = {{{template talk|{{#ifeq: {{{empty|}}}|yes| |template talk page}}}}}
   | 11 = {{{template talk|{{{others|template talk page}}}}}}
   | 12 = {{{help|{{#ifeq: {{{empty|}}}|yes| |help page}}}}}
   | 12 = {{{help|{{{others|help page}}}}}}
   | 13 = {{{help talk|{{#ifeq: {{{empty|}}}|yes| |help talk page}}}}}
   | 13 = {{{help talk|{{{others|help talk page}}}}}}
   | 14 = {{{category|{{#ifeq: {{{empty|}}}|yes| |category}}}}}
   | 14 = {{{category|{{{others|category}}}}}}
   | 15 = {{{category talk|{{#ifeq: {{{empty|}}}|yes| |category talk page}}}}}
   | 15 = {{{category talk|{{{others|category talk page}}}}}}
   | 1280 = {{{sim|{{#ifeq: {{{empty|}}}|yes| |sim}}}}}
   | 1280 = {{{sim|{{{others|sim}}}}}}
   | 1281 = {{{sim talk|{{#ifeq: {{{empty|}}}|yes| |sim talk page}}}}}
   | 1281 = {{{sim talk|{{{others|sim talk page}}}}}}
   | page
   | page
}}</includeonly><noinclude>
}}</includeonly><noinclude>
Line 30: Line 30:


Full usage:
Full usage:
<pre>{{Namespace|page= |empty= |main= |talk= |user= |user talk= |118wiki= |118wiki talk= |file= |file talk= |mediawiki= |mediawiki talk= |template= |template talk= |help= |help talk= |category= |category talk= |sim= |sim talk= }}</pre>
<pre>{{Namespace|page= |others= |main= |talk= |user= |user talk= |118wiki= |118wiki talk= |file= |file talk= |mediawiki= |mediawiki talk= |template= |template talk= |help= |help talk= |category= |category talk= |sim= |sim talk= }}</pre>


At basic use, the template will print a reader-friendly name for the namespace of the page the template is placed in.
At basic use, the template will print a reader-friendly name for the namespace of the page the template is placed in.
Line 80: Line 80:
'''page''' parameter can be used to determine from which page the namespace is taken. If left empty, takes the namespace of the current page. Note that this parameter doesn't check if the page actually exists!
'''page''' parameter can be used to determine from which page the namespace is taken. If left empty, takes the namespace of the current page. Note that this parameter doesn't check if the page actually exists!


'''empty''' parameter empties all predefined namespace dependent values, in which case the template doesn't return anything on pages in namespaces for which you haven't defined a new value. Write "yes" if you don't want to use the predefined values.
'''others''' parameter determines the content displayed on every namespace except those that have a custom text. If left empty, the nothing will appear on pages in namespace other than those defined.


== Examples ==
== Examples ==
Line 110: Line 110:
Note that if you place this template to a page other than article, file or template, it will print the namespace name as usual. For example, on a talk page, this is what you would get:
Note that if you place this template to a page other than article, file or template, it will print the namespace name as usual. For example, on a talk page, this is what you would get:
{{Ambox | type=notice | text={{namespace|main=You can edit articles like this one by clicking "edit" or "edit source" on top of the page.|file=You can upload a new version of this file by clicking "Upload a new version of this file". To edit the file information page, click "edit" or "edit source".|template=Templates can only be edited with the source editor.|page=Talk:Example}}}}
{{Ambox | type=notice | text={{namespace|main=You can edit articles like this one by clicking "edit" or "edit source" on top of the page.|file=You can upload a new version of this file by clicking "Upload a new version of this file". To edit the file information page, click "edit" or "edit source".|template=Templates can only be edited with the source editor.|page=Talk:Example}}}}
If this is not something you want, empty all other values with parameter "empty":
If this is not something you want, empty all other values with parameter "others":
<pre>{{Ambox  
<pre>{{Ambox  
| type=notice  
| type=notice  
| text='''{{namespace
| text='''{{namespace
   |empty=yes
   |others=
   |main=You can edit articles like this one by clicking "edit" or "edit source" on top of the page.
   |main=You can edit articles like this one by clicking "edit" or "edit source" on top of the page.
   |file=You can upload a new version of this file by clicking "Upload a new version of this file". To edit the file information page, click "edit" or "edit source".
   |file=You can upload a new version of this file by clicking "Upload a new version of this file". To edit the file information page, click "edit" or "edit source".
Line 120: Line 120:
}}</pre>
}}</pre>
Now, you get:
Now, you get:
{{Ambox | type=notice | text={{namespace|empty=yes|main=You can edit articles like this one by clicking "edit" or "edit source" on top of the page.|file=You can upload a new version of this file by clicking "Upload a new version of this file". To edit the file information page, click "edit" or "edit source".|template=Templates can only be edited with the source editor.}}}}
{{Ambox | type=notice | text={{namespace|others=|main=You can edit articles like this one by clicking "edit" or "edit source" on top of the page.|file=You can upload a new version of this file by clicking "Upload a new version of this file". To edit the file information page, click "edit" or "edit source".|template=Templates can only be edited with the source editor.}}}}
And on a talk page:
And on a talk page:
{{Ambox | type=notice | text={{namespace|empty=yes|main=You can edit articles like this one by clicking "edit" or "edit source" on top of the page.|file=You can upload a new version of this file by clicking "Upload a new version of this file". To edit the file information page, click "edit" or "edit source".|template=Templates can only be edited with the source editor.|page=Talk:Example}}}}
{{Ambox | type=notice | text={{namespace|others=|main=You can edit articles like this one by clicking "edit" or "edit source" on top of the page.|file=You can upload a new version of this file by clicking "Upload a new version of this file". To edit the file information page, click "edit" or "edit source".|template=Templates can only be edited with the source editor.|page=Talk:Example}}}}


The custom value can also be formatted, another template, category or something else.
The custom value can also be formatted, another template, category or something else.

Latest revision as of 20:15, 2 March 2024

Template Documentation
This is a metatemplate that can be used in other templates to identify the namespace of a page or to trigger a specific response depending on the namespace.

Not to be confused with wiki magic word {{NAMESPACE}}.

Usage

Basic usage:

{{Namespace}}

Full usage:

{{Namespace|page= |others= |main= |talk= |user= |user talk= |118wiki= |118wiki talk= |file= |file talk= |mediawiki= |mediawiki talk= |template= |template talk= |help= |help talk= |category= |category talk= |sim= |sim talk= }}

At basic use, the template will print a reader-friendly name for the namespace of the page the template is placed in.

{{Namespace}}

Result: template

If you want that the template produces something else in a specific namespace, use the parameter with appropriate name. Note that the parameters are in lower case.

Namespace Parameter Default print
(main) main= article
Talk talk= talk page
User user= user page
User talk user talk= user talk page
118Wiki 118wiki= project page
118Wiki talk 118wiki talk= project talk page
File file= file
File talk file talk= file talk page
MediaWiki mediawiki= MediaWiki system page
MediaWiki talk mediawiki talk= MediaWiki system talk page
Template template= template
Template talk template talk= template talk page
Help help= help page
Help talk help talk= help talk page
Category category= category
Category talk category talk= category talk page
SIM sim= sim
SIM talk sim talk= sim talk page

page parameter can be used to determine from which page the namespace is taken. If left empty, takes the namespace of the current page. Note that this parameter doesn't check if the page actually exists!

others parameter determines the content displayed on every namespace except those that have a custom text. If left empty, the nothing will appear on pages in namespace other than those defined.

Examples

Basic template text

Let's say you want to create a message box that informs the reader of a content problem on the page. You want the template to know what type of a page it is placed in.

{{Ambox 
| type=content 
| text='''This {{namespace}} has problems''' <br> <small>Fix them!</small>}}

Since this is a template page, you will get the following result:

If you put that template to an article (main namespace), the result would automatically be like this:

Template custom text

Let's say you want to create a message box that gives instructions how to edit a specific types of pages. For example's sake, let's say you want the template to explain articles, files and templates.

{{Ambox 
| type=notice 
| text='''{{namespace
  |main=You can edit articles like this one by clicking "edit" or "edit source" on top of the page.
  |file=You can upload a new version of this file by clicking "Upload a new version of this file". To edit the file information page, click "edit" or "edit source".
  |template=Templates can only be edited with the source editor.}}
}}

On a file page:

In an article:

Note that if you place this template to a page other than article, file or template, it will print the namespace name as usual. For example, on a talk page, this is what you would get:

If this is not something you want, empty all other values with parameter "others":

{{Ambox 
| type=notice 
| text='''{{namespace
  |others=
  |main=You can edit articles like this one by clicking "edit" or "edit source" on top of the page.
  |file=You can upload a new version of this file by clicking "Upload a new version of this file". To edit the file information page, click "edit" or "edit source".
  |template=Templates can only be edited with the source editor.}}
}}

Now, you get:

And on a talk page:

The custom value can also be formatted, another template, category or something else.