साँचा:Main talk other/doc

मुक्त ज्ञानकोश विकिपीडिया से
नेविगेशन पर जाएँ खोज पर जाएँ

{{

 साँचा:namespace detect

| type = notice | image = | imageright = | class = | style = margin-bottom:1.0em; | textstyle = | text = साँचा:strong for साँचा:terminate sentence
It contains usage information, categories and other content that is not part of the original साँचा page. | small = | smallimage = | smallimageright = | smalltext = | subst = | date = | name = }}

This is the साँचा:tl 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 Wikipedia into three types:

main = Main/article space, as in normal Wikipedia articles.
talk = Any talk space, such as page names that start with "Talk:", "User talk:", "Image talk:" and so on.
other = All other spaces, such as page names that start with "User:", "Image:", "Wikipedia:" and so on.

This page is also the documentation for some other templates:

  • साँचा:tl – It works exactly the same, but it has some minor internal differences. Read more about that below.
  • साँचा:tl – It works exactly the same, apart from that it uses the type category for pages that start with "Category:", but it still uses the type talk for "Category talk:" pages.

Basic functionality

If this template is used without any parameters it returns the type name that the page belongs to: main, talk or other.

This template page (and its doc page) belongs to the type "other". Thus this code on this page:

साँचा:tlc

renders like this:

साँचा:main talk other

This template can also take three parameters and then returns one of them depending on which type a page belongs to. Like this:

साँचा:tlc

which renders like this:

साँचा:main talk other

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:

साँचा:tlc
साँचा:tlc

Then it doesn't render anything in mainspace and other space.

The extended साँचा:tl template instead takes four parameters, also in the same order as the words in its name. Like this:

साँचा:tlc

which renders like this:

साँचा:main talk category other

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 HTML tables and numbered parameters, for the reasons why see the next section.

{{main talk other
| 1 = ''This messagebox should not be used in articles.''
| 2 =
  <table class="messagebox standard-talk">
  <tr><td>[[Image:Info talk.png|40px]]
  <td>Talk page messagebox
  </table>
| 3 =
  <table class="messagebox">
  <tr><td>[[Image:Info_talk.png|40px]]
  <td>Other pages messagebox
  </table>
}}

Which renders like this:

साँचा:main talk other

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:

साँचा:main talk other

And now let's test it for article pages:

{{main talk other|demospace=main

This is how it will render in an article:

साँचा:main talk other
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.

If the message box above should be used in articles too then the code for the first parameter should be something like this:

| 1 =
  {{ambox
  | type = notice
  | text = Article message box
  }}

Technical details

HTML tables and numbered parameters

Templates do have a problem to handle parameter data that contains pipes "|", unless the pipe is inside another template {{name|param1}} or inside a piped link [[Help:Template|help]]. Thus templates can not handle wikitables as input unless you escape them by using the साँचा:tn 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.

Templates also have a problem to handle parameter data that contains equal signs "=". But that is easily solved by using numbered parameters, such as "1=First parameter" and "2=Second parameter".

Comparison

साँचा:tl and साँचा:tl behaves exactly the same but internally uses different code:

  • साँचा:tld will still correctly detect all talk pages even if new namespaces are added to Wikipedia. The talk page and main space detection functions are also shorter and thus nicer if you want to copy them to use them elsewhere:
साँचा:nowrap
साँचा:nowrap
  • साँचा:tld is more flexible in that its code is much easier to modify to detect any combination of namespaces as one wishes. But please copy the code to a new template before you do such modifications.
  • If a new namespace is added to Wikipedia then साँचा:tld needs to be manually updated, otherwise it will detect the new talk space as type "other". Fortunately new namespaces is a very rare event.

So if you just need to detect main, talk and other then use साँचा:tld. But if you want to detect other combinations then copy the code from साँचा:tld.

साँचा:tl also will correctly detect all talk pages even if new namespaces are added to Wikipedia.

Copying to other projects?

If you copy these templates to another language Wikipedia or other Wikimedia project, then साँचा:tld should work as is, but you probably want to update the template's name and its parameter names to your local namespace naming. But you must update the code of साँचा:tld and साँचा:tld to your local naming and add any extra namespaces that are local to your wiki, otherwise they will malfunction.

CSS namespace detection

CSS code can be used instead of these templates to detect namespaces. This can be used for those things that can be coded as CSS, such as colours and borders. See example on the talk page.

See also

Technical stuff:

Examples: