ထႅမ်းပလဵတ်ႉ:Main talk other
This is the {{Main talk other}} meta-template.
This template is used inside other templates that need to behave differently (usually look differently) depending on what type of page they are on. It detects and groups all the different namespaces used on Wikibooks into three types:
- main = Main/book space, as in normal Wikibooks pages.
- talk = Any talk space, such as page names that start with "Talk:", "User talk:", "File talk:" and so on.
- other = All other spaces, such as page names that start with "User:", "File:", "Wikibooks:" and so on.
Basic usage
[မႄးထတ်း]This template usually takes three parameters, and returns one of them depending on which type a page belongs to. Like this:
{{main talk other|Book text|Talk page text|Other pages text}}
If the template is on a main space (book) page, it will return this:
- Book text
If the template is on any talk page, it will return this:
- Talk page text
If the template is on any other page (such as this template page and its doc page), it will return this:
- Other pages text
If you only feed a parameter for one or two of the types then this template returns an empty string for the rest of the types. That is, if it for instance is used in one of these ways:
{{main talk other|Talk text}}
{{main talk other|Talk text}}
Then it doesn't render anything in mainspace and other space.
If this template is used without any parameters or only fed empty parameters (empty strings), then it returns an empty string. That is, then it renders nothing.
For testing and demonstration purposes these templates can take a parameter named demospace: if it has any of the values main, talk or other it makes the template behave as if it is on a page of that type; if the parameter is empty or undefined, the actual page type determines the result.
Usage example
[မႄးထတ်း]This example creates a message box, but these templates can of course be used for many other things than message boxes. This example uses numbered parameters and HTML tables, for the reasons why see the technical details section below.
{{Main talk other | 1 = ''This messagebox should not be used in articles.'' | 2 = {{Tmbox|text=Talk page notice}} | 3 = {{Ombox|text=Other pages notice}} }}
Which renders like this:
Other pages notice |
Let's see how it looks on talk pages. So we change the first line in the code to this:
{{Main talk other|demospace=talk
This is how it will render on any talk page:
Talk page notice |
And now let's test it for book pages:
{{Main talk other|demospace=main
This is how it will render in a book:
This messagebox should not be used in books.
Additional code
[မႄးထတ်း]Too make this example complete, here is the rest of the code that is needed to make it a fully equipped template:
{{Main talk other | demospace = {{{demospace|}}} | 1 = | 2 = | 3 = }}<noinclude> {{Documentation}} <!-- Add categories and interwikis to the /doc subpage, not here! --> </noinclude>
The line "| demospace = {{{demospace|}}}
" means that your template also will understand the demospace parameter. That means you can demonstrate the different appearances of your template in the documentation for your template.
The "{{documentation}}
" template creates a green documentation box, like the one you are reading in right now.
Technical details
[မႄးထတ်း]Numbered parameters and HTML tables
[မႄးထတ်း]Templates have a problem handling parameter data that contains equal signs "=
". But that is easily solved by using numbered parameters, such as "1=First parameter
" and "2=Second parameter
".
Templates also have a problem handling parameter data that contains pipes "|
", unless the pipe is inside another template {{name|param1}}
or inside a piped link [[လွင်ႈၸွႆႈထႅမ်:Templates|help]]
. Thus templates can not handle wikitables as input unless you escape them by using the {{!}} template. This makes it hard to use wikitables as parameters to templates. Instead the usual solution is to use "HTML wikimarkup" for the table code, which is more robust.
တူၺ်းပႃး
[မႄးထတ်း]Easy to use namespace-detection templates:
- {{Main other}} – For book page templates.
- {{Talk other}} – For talk page templates.
- {{User other}} – For user page templates.
- {{Wikibooks other}} – For project page templates.
- {{Subject other}} - For subject page templates.
- {{File other}} – For file (image) templates.
- {{Template other}} – For detecting template pages.
- {{Help other}} – For help page templates.
- {{Category other}} – For category templates.
- {{Wikijunior other}} – For Wikijunior templates.
- {{Cookbook other}} – For Cookbook templates.
More complex namespace-detection templates:
- {{Namespace detect}} – The very versatile one.
- {{Namespace detect showall}} – The extremely versatile one; has input reuse.
- {{Talkspace detect}} - For detecting talk pages on various namespaces.
- {{Main talk other}} – Separates some namespaces.
Pagename-handling and detection templates:
- {{Basepage subpage}} – For detecting if on a basepage, subpage, or subsubpage.
- {{If pagename}} – For pattern matching on the pagename.
- {{IP-user other}} – For detecting IP-user pages.