Difference between revisions of "Help:Template"

(Creating Templates)
(Creating Templates)
Line 41: Line 41:
 
Of course, sequential parameters, like named parameters, must be separated by a pipe. And just like named parameters, you could place the parameters on separate lines.
 
Of course, sequential parameters, like named parameters, must be separated by a pipe. And just like named parameters, you could place the parameters on separate lines.
  
=Creating Templates=
+
Hanoi PhuDo hotel.
Before you create your template, make sure the template doesn't already exist by going to <span class="plainlinks">[http://www.aboutus.org/index.php?title=Special%3APrefixindex&from=&namespace=10 Special:Prefixindex]</span> and selecting Template from the namespace drop-down box.
 
 
 
When you are ready to create your template, go to <code style="font-size: 10pt"><nowiki>http://www.aboutus.org/Template:NameOfNewTemplate</nowiki></code> (replacing NameOfNewTemplate with whatever you wish to call it). Make sure that the name of the template is not too long, but is descriptive enough of its function, and the name is easy enough to remember.
 
 
 
Your template can be simple, like <code style="font-size: 10pt">{{TemplateEditLink|smiley}}</code>, or as complex as <code style="font-size: 10pt">{{TemplateEditLink|CategoryTOC}}</code>.
 
 
 
==MagicWords==
 
MagicWords can be considered a predefined template without parameters.
 
 
 
This is a list of MagicWords that can be used in the wikitext. The way they are rendered vary with time (directly depending on time, or e.g. for number of articles, depending on the creation of other articles), on the project (it changes when the wikitext is copied), or on the page in which it occurs (it changes when the wikitext is copied, when the page is renamed, and when the page is included in another page).
 
 
 
[[#List_of_MagicWords|List of Words]]
 
 
 
==Receiving Passed Parameters==
 
===Named Parameters===
 
Receiving passed parameters to a template is very easy. All you have to do is surround the name of the parameter in triple quotes where you want it in the template. For example, a template which would show the contents of the <code style="font-size: 10pt">text</code> parameter would be coded like this:
 
 
 
<pre style="font-size: 10pt"><nowiki>{{{text}}}</nowiki></pre>
 
 
 
===Sequential Parameters===
 
Sequential parameters are quite the same thing, only you would use the number of the parameter, which starts at 1:
 
 
 
<pre style="font-size: 10pt"><nowiki>{{{1}}}</nowiki></pre>
 
 
 
You ''can'' put the parameters in any order you want, for example:
 
 
 
<pre style="font-size: 10pt"><nowiki>{{{1}}} is a {{{2}}}. {{{1}}} likes {{{3}}}.</nowiki></pre>
 
 
 
===Default Values===
 
 
 
If you want to have a default value for the parameter, which is shown if the template is embedded without specifying the parameter, you can add a pipe ( <code style="font-size: 10pt">|</code> ) to the end of the name of the parameter, followed by the default value. For example,
 
 
 
<pre style="font-size: 10pt"><nowiki>{{{text|Default Value}}}</nowiki></pre>
 
 
 
====Important Notes====
 
When a parameter is not passed, and there is no default value, the parameter will be read as text. That means that <code style="font-size: 10pt">{{{x}}}</code>, replacing x with the name of the parameter being used will be seen in the place it is used.
 
 
 
==List of MagicWords==
 
===Constants===
 
 
 
{|
 
| <code><nowiki>{{SITENAME}}</nowiki></code>
 
| {{SITENAME}}
 
|-
 
| <code><nowiki>{{SERVER}}</nowiki></code>
 
| {{SERVER}}
 
|-
 
| <code><nowiki>{{SERVERNAME}}</nowiki></code>
 
| {{SERVERNAME}}
 
|-
 
| <code><nowiki>{{CONTENTLANGUAGE}}</nowiki></code>
 
| {{CONTENTLANGUAGE}}
 
| code of the site's default interface language
 
|}
 
 
 
===Dependent on page===
 
{| class="wikitable" border="2" cellpadding="4" cellspacing="0"
 
! Word
 
! Example
 
! Explanation
 
|-
 
| <nowiki>{{PAGENAME}}</nowiki>
 
| <code>{{PAGENAME}}</code>
 
| Returns the name of the current page, including all levels (Title/Subtitle).
 
|-
 
| <nowiki>{{PAGENAMEE}}</nowiki>
 
| <code>{{PAGENAMEE}}</code>
 
| More URL-friendly percent encoded special characters (To use an articlename in an external link).
 
|-
 
| <nowiki>{{SUBPAGENAME}}</nowiki><br /><nowiki>{{SUBPAGENAMEE}}</nowiki>
 
| <code>{{SUBPAGENAME}}<br />{{SUBPAGENAMEE}}</code>
 
| '''[MW1.6+]''' Name of the current page, excluding parent pages ("Subtitle" on "Title/Other/Subtitle") in namespaces supporting subpages, see [[Help:Link#Subpage feature|Help:Link]].
 
|-
 
| <nowiki>{{BASEPAGENAME}}</nowiki><br ><nowiki>{{BASEPAGENAMEE}}</nowiki>
 
| <code>{{BASEPAGENAME}}<br />{{BASEPAGENAMEE}}</code>
 
| '''[MW1.7+]''' The basename of a subpage ("Title/Other" on "Title/Other/Subtitle"), see [[Help:Link#Subpage feature|Help:Link]].
 
|-
 
| <nowiki>{{NAMESPACE}}</nowiki><br /><nowiki>{{NAMESPACEE}}</nowiki>
 
| <code>{{NAMESPACE}}<br />{{NAMESPACEE}}</code>
 
| Returns the name of the namespace the current page resides in.
 
|-
 
| <nowiki>{{FULLPAGENAME}}</nowiki><br ><nowiki>{{FULLPAGENAMEE}}</nowiki>
 
| <code>{{FULLPAGENAME}}<br />{{FULLPAGENAMEE}}</code>
 
| '''[MW1.6+]''' Shorthands for NAMESPACE+PAGENAME
 
|-
 
| <nowiki>{{TALKSPACE}}</nowiki><br ><nowiki>{{TALKSPACEE}}</nowiki>
 
| <code>{{TALKSPACE}}<br />{{TALKSPACEE}}</code>
 
| '''[MW1.7+]''' Name of next odd namespace (e.g. 4 =&gt; 5)
 
|-
 
| <nowiki>{{SUBJECTSPACE}}</nowiki><br ><nowiki>{{SUBJECTSPACEE}}</nowiki>
 
| <code>{{SUBJECTSPACE}}<br />{{SUBJECTSPACEE}}</code>
 
| '''[MW1.7+]''' Name of last even namespace (e.g. 5 =&gt; 4)
 
|-
 
| <nowiki>{{ARTICLESPACE}}</nowiki><br ><nowiki>{{ARTICLESPACEE}}</nowiki>
 
| <code>{{ARTICLESPACE}}<br />{{ARTICLESPACEE}}</code>
 
| '''[MW1.7+]''' An alias for SUBJECTSPACE(E)
 
|-
 
| <nowiki>{{TALKPAGENAME}}</nowiki><br ><nowiki>{{TALKPAGENAMEE}}</nowiki>
 
| <code>{{TALKPAGENAME}}<br />{{TALKPAGENAMEE}}</code>
 
| '''[MW1.7+]''' FULLPAGENAME in its TALKSPACE
 
|-
 
| <nowiki>{{SUBJECTPAGENAME}}</nowiki><br ><nowiki>{{SUBJECTPAGENAMEE}}</nowiki>
 
| <code>{{SUBJECTPAGENAME}}<br />{{SUBJECTPAGENAMEE}}</code>
 
| '''[MW1.7+]''' FULLPAGENAME in its SUBJECTSPACE
 
|-
 
| <nowiki>{{ARTICLEPAGENAME}}</nowiki><br ><nowiki>{{ARTICLEPAGENAMEE}}</nowiki>
 
| <code>{{ARTICLEPAGENAME}}<br />{{ARTICLEPAGENAMEE}}</code>
 
| '''[MW1.7+]''' An alias for SUBJECTPAGENAME(E)
 
|-
 
| <nowiki>{{REVISIONID}}</nowiki>
 
| <code>{{REVISIONID}}</code>
 
| '''[MW1.5+]''' The unique identifying number of a page, see [[Help:Diff]].  Note that when editing a page, this value is null.
 
|-
 
| <nowiki>{{REVISIONDAY}}</nowiki>
 
| <code>{{REVISIONDAY}}</code>
 
| '''[MW1.8+]''' The day on which the page was last modified.
 
|-
 
| <nowiki>{{REVISIONDAY2}}</nowiki>
 
| <code>{{REVISIONDAY2}}</code>
 
| '''[MW1.8+]''' The day on which the page was last modified, but with a leading zero (01 .. 31).
 
|-
 
| <nowiki>{{REVISIONMONTH}}</nowiki>
 
| <code>{{REVISIONMONTH}}</code>
 
| '''[MW1.8+]''' The month in which the page was last modified.
 
|-
 
| <nowiki>{{REVISIONYEAR}}</nowiki>
 
| <code>{{REVISIONYEAR}}</code>
 
| '''[MW1.8+]''' The year in which the page was last modified.
 
|-
 
| <nowiki>{{REVISIONTIMESTAMP}}</nowiki>
 
| <code>{{REVISIONTIMESTAMP}}</code>
 
| '''[MW1.8+]''' [[Wikipedia:ISO 8601|ISO 8601]] time stamp, indicating when the page was last modified.
 
|-
 
| <nowiki>{{SITENAME}}</nowiki>
 
| <code>{{SITENAME}}</code>
 
| Value of $Sitename.
 
|-
 
| <nowiki>{{SERVER}}</nowiki>
 
| <small>{{SERVER}}</small>
 
| Value of $Server
 
|-
 
| <nowiki>{{SCRIPTPATH}}</nowiki>
 
| <code>{{SCRIPTPATH}}</code>
 
| '''[MW1.5+]''' $ScriptPath
 
|-
 
| <nowiki>{{SERVERNAME}}</nowiki>
 
| <code>{{SERVERNAME}}</code>
 
| '''[MW1.5+]''' $ServerName
 
|-
 
|}
 

Revision as of 10:09, 21 November 2008

A template is a wiki page whose contents are specially intended to be inserted into another wiki page by the "transclusion" process. When you use a template, the template name is surrounded in double curly braces: {{NameOfTemplate}}.

If you're interested in using templates, just keep reading. If you're interesting in creating them, see the Creating Templates section of this page.

Using Templates

Passing Parameters

Named Parameters

Named parameters are parameters which have a name to them. For example, the {{DomainPage}} template uses named parameters. To use the DomainPage template, you would use code such as the following:

{{ Domain_Page |
 reviews = <reviews></reviews> |
 vote = <vote></vote> |
 thumbnail = <thumbnail>AboutUs.org</thumbnail> |
 map = <map section="Address"></map>
}}

Do not be confused in this example - the tags being passed, such as <reviews></reviews>, are not necessary to pass named parameters. The tags themselves are being passed to the template.

In this example, reviews, vote, thumbnail, and map are all named parameters, because you must specify their name. Named parameters need to have an equal sign ( = ) between the name of the parameter and the value.

Notice how there is a pipe ( | ) at the end of each line. This separates the previous parameter from the next. Now you are probably thinking, "then why do we need a pipe if we need to place the parameters on separate lines?" The thing is, you don't have to put them on separate lines. You can if you want. This template could be condensed into one line:
And there it goes.......... -->
{{ Domain_Page|reviews = <reviews></reviews>|vote = <vote></vote>|thumbnail = <thumbnail>AboutUs.org</thumbnail>|map = <map section="Address"></map>}}

Sequential Parameters

Sequential parameters do not have a name to them. It all matters in what order you pass them. For example, the {{color}} template engages sequential parameters. To use this template you would use:

{{color|Black|Blah blah blah blah blah.}}

Because this template is using sequential parameters, switching the two around (Black) would not give the desired output.

But then, how would you skip a parameter? Very simple. Simply leave a blank value. For example, Blah blah blah blah blah. (notice that the color parameter is skipped).

Of course, sequential parameters, like named parameters, must be separated by a pipe. And just like named parameters, you could place the parameters on separate lines.

Hanoi PhuDo hotel.