వికీపీడియా:Anatomy of a template
ఈ పేజీ, వికీపీడియా లోని ఒక విశేషం గురించీ దాన్ని అమలు చేసే విధానం గురించీ వివరించే ఎలా చెయ్యాలి అనే మార్గసూచిక లోని భాగం. |
Templates on Wikipedia can be used for a variety of purposes. Some common uses for templates include infoboxes to summarize the information presented in an article, while others are information messages.
Templates are created in the Template: namespace, which means that a fictitious template called Shelf would be located on page http://en.wikipedia.org/wiki/Template:Shelf. In this way, template names do not conflict with the names of articles, images, and other elements on Wikipedia.
Template names are added to pages inside double curly brackets. In addition, user-typed parameters are allowed, so that the template has some input to work with. The parameters allow the templates to be tailored to the specific needs of different articles and pages. When the page is previewed or saved, the result or output of the template will be found in place of the template code.
A typical page entry for a template with two parameters takes the form:
{{TemplateName|Parameter1|Parameter2}}
or using named parameters:
{{TemplateName|a=Parameter1|b=Parameter2}}
For the discussion below we will make use of a popular template: {{current}}. The former code for {{current}} is shown in the block below:
{| class="messagebox current" style="width: auto;" | [[Image:Current event marker.svg|50px| ]] | '''This {{{1|article}}} documents a [[Portal:Current events|current event]].''' <br> <small>Information may change rapidly as the event progresses.</small> |}{{#if:{{NAMESPACE}}|<!-- don't categorize -->|[[Category:Current events]]}}<noinclude> ==See also== *[[Template:Current-related]] *[[Template:Current-section]] [[Category:Temporal templates|{{PAGENAME}}]] [[ar:قالب:حدث جاري]] [[de:Vorlage:Neuigkeiten]] [[it:Template:Incorso]] [[no:mal:Pågående]] [[pl:Szablon:Aktualne]] [[vi:Tiêu bản:Đang diễn ra]] [[eu:Txantiloi:Eguneratu]] </noinclude>
Parameters
[మార్చు]As you can see, one can put almost anything in a template – text, images, tables, colors, ... you name it. One will need to be familiar with other wiki markup if one wants to make templates that are especially complex. Nevertheless, the beginning of the third line – {{{1|article}}} is what we will focus on first. This is how a parameter is included. It essentially says that if there is an unnamed parameter added to the inclusion of the {{current}} template, it will appear in that location. Otherwise, article will appear there instead. {{current}} produces...
ఈ వ్యాసం, వర్తమాన ఘటనను వివరిస్తుంది. సమయం గడిచే కొద్దీ సమాచారం వేగంగా మారిపోయే అవకాశం ఉంది. |
...while {{current|cha-cha}} produces...
ఈ cha-cha, వర్తమాన ఘటనను వివరిస్తుంది. సమయం గడిచే కొద్దీ సమాచారం వేగంగా మారిపోయే అవకాశం ఉంది. |
Of course, the writers of {{current}} probably intended section or something to that effect to be used as the parameter. Note how parameters have three curly brackets on each side of them; those items with two brackets are templates and variables embedded into the {{current}} template.
Conditionals
[మార్చు]Take a look at the fifth line in {{current}}. You'll see something that says {{#if:{{NAMESPACE}}|<!-- don't categorize -->|[[Category:Current events]]}}. This is a conditional statement and the #if function assists with the construction, which involves three parameters – a test statement, a result when the test statement is true, and a result when the test statement is false. In this case, if the location of the page is preceded by a namespace – Wikipedia:, Talk:, User:, etc. – the test statement will return true and produce what immediately follows the first pipe character (|), which in the example here is a comment (the text between the <!-- and --> become hidden from view by web page viewers). If no namespace precedes the page, the test statement returns false and produces what immediately follows the second pipe character – a category, [[Category:Current events]].
Another example of a conditional in {{current}} is in line three, with {{{1|article}}}. The pipe character (|) indicates that if the parameter name or number indicated on the left side does not exist, the text on the right will appear instead. Note also another example, {{{1|{{article}}}}} (which does not exist in {{current}}), which returns a template by the name of article if the first item does not exist. Furthermore, note that {{{1|{{{article}}}}}} would produce parameter article if false. So, in summary...
Conditional | Result, if True | Result, if False |
{{{a|b}}} | parameter named a | text b |
{{{a|{{b}}}}} | parameter named a | template entitled b |
{{{a|{{b|c}}}}} | parameter named a | template entitled b, with unnamed parameter c |
{{{a|{{b|c=d}}}}} | parameter named a | template entitled b, with parameter d named c |
{{{a|{{{b}}}}}} | parameter named a | parameter named b |
{{{a|{{{b|c}}}}}} | parameter named a | embedded conditional similar to prescribed {{a|b}} |
As you can see by the last example, conditionals can even be embedded within other conditionals. Note also that #ifexpr: is needed for mathematical expressions.
<noinclude>
[మార్చు]Everything in a template will be transcluded when added to a page, unless the content is between <noinclude> and </noinclude> tags. Thus, see also links (e.g. Template:Current-related and Template:Current-section), interlanguage links (e.g. ), and categories that belong to the template itself rather than the pages on which the template will placed (e.g. [[Category:Temporal templates|{{PAGENAME}}]]) belong between the <noinclude> tags.
<includeonly>
[మార్చు]<includeonly> is sort-of the inverse of <noinclude>. Everything enclosed in a <includeonly> tag will not be displayed in the template page, but will be transcluded into another page. This has several uses:
- A page containing the template needs to be in a category the template itself does not belong in.
- A word, description or some other chunk is meaningless on the template page that holds meaning on a page using the template, such as a table format, part of an equation, et cetera...
See also
[మార్చు]Extensive tutorials
[మార్చు]- Help:Template – a more extensive page on creating templates
- m:Help:Advanced templates – a very, very extensive page on creating templates
Other pages
[మార్చు]- Help:Calculation – assistance with calculations
- m:Help:Parameter default – some help with parameters
- MediaWiki Parser Functions – more information on parser and conditional functions
- Wikipedia:Template list of Wikipedia templates
- Help:Variable – a look at variables