Difference between revisions of "Help:Template namespace"

MyWikiBiz, Author Your Legacy — Sunday December 01, 2024
Jump to navigationJump to search
 
Line 2: Line 2:
 
    
 
    
 
== Introduction ==
 
== Introduction ==
Templates often look like text boxes with a different background color from that of normal text. They are in the [[Centiare:Template namespace|template namespace]], i.e. they are defined in pages with "Template:" in front of the name.
+
Templates often look like text boxes with a different background color from that of normal text. They are in the [[Help:Template namespace|template namespace]], i.e. they are defined in pages with "Template:" in front of the name.
  
 
Templates can accept template parameters which are then inserted into the output of the template.   
 
Templates can accept template parameters which are then inserted into the output of the template.   
Line 8: Line 8:
 
Templates in the article namespace provide information to help readers.  These can include navigation aids, or warnings that content is sub-standard. Templates that provide information only of service to editors belong on an article's talk page.   
 
Templates in the article namespace provide information to help readers.  These can include navigation aids, or warnings that content is sub-standard. Templates that provide information only of service to editors belong on an article's talk page.   
  
With the '''template [Centiare:namespace|]]''' it is possible to include the contents of a page in that namespace within a page in a different namespace, using double curly braces around the template title (for example, <nowiki>{{title}}</nowiki> would import [[Template:Title]]). This is used to:
+
With the '''template [Help:namespace|]]''' it is possible to include the contents of a page in that namespace within a page in a different namespace, using double curly braces around the template title (for example, <nowiki>{{title}}</nowiki> would import [[Template:Title]]). This is used to:
 
* place recurring messages (such as those to denote [[stubs]], disambiguation pages, etc.) into articles in a consistent manner;
 
* place recurring messages (such as those to denote [[stubs]], disambiguation pages, etc.) into articles in a consistent manner;
 
* insert [[Boilerplate (text)|boilerplate messages]] for various issues like copyright violation, neutrality disputes, etc., using a simple shortcut command; and
 
* insert [[Boilerplate (text)|boilerplate messages]] for various issues like copyright violation, neutrality disputes, etc., using a simple shortcut command; and
* create [[Centiare:Navigational templates|navigational templates and sidebars]] to link series of related articles together.
+
* create [[Help:Navigational templates|navigational templates and sidebars]] to link series of related articles together.
* create [[Centiare:Infobox templates|infoboxes]]
+
* create [[Celp:Infobox templates|infoboxes]]
  
 
Templates should not masquerade as article content in the main article namespace; instead, place the text directly into the article.
 
Templates should not masquerade as article content in the main article namespace; instead, place the text directly into the article.
  
Templates should also not be used to create lists of links to other articles when a [[Centiare:Categories|category]] or a [[Centiare:See also|See also list]] can perform the same function.
+
Templates should also not be used to create lists of links to other articles when a [[Help:Categories|category]] or a [[Help:See also|See also list]] can perform the same function.
  
 
=== Template creation ===
 
=== Template creation ===
To create a new custom message, simply create a page in the Template namespace, named "Template:", followed by a name for the message, that contains the text of the message.  Names can now contain spaces and initial case is irrelevant.  An alternate method is to create a link something like '''<nowiki>[[Template:mymessage]]</nowiki>''' on your user page or in the [[Centiare:Sandbox|sandbox]] and then click on it.  You may want to consider protecting the messages you create (if you have administrator privileges), but see the [[Centiare talk:Template messages|talk page]] for a discussion of this. Please list any custom messages you create on this page.
+
To create a new custom message, simply create a page in the Template namespace, named "Template:", followed by a name for the message, that contains the text of the message.  Names can now contain spaces and initial case is irrelevant.  An alternate method is to create a link something like '''<nowiki>[[Template:mymessage]]</nowiki>''' on your user page or in the [[Help:Sandbox|sandbox]] and then click on it.  You may want to consider protecting the messages you create (if you have administrator privileges), but see the [[MyWikiBiz talk:Template messages|talk page]] for a discussion of this. Please list any custom messages you create on this page.
  
 
=== Usage ===
 
=== Usage ===
Line 35: Line 35:
  
 
=== Dynamic or subst ===
 
=== Dynamic or subst ===
:''Main article: [[Centiare:Template substitution]]''
+
:''Main article: [[Help:Template substitution]]''
  
 
There are two major ways to include custom messages, <tt>'''<nowiki>{{Your message}}</nowiki>'''</tt> and <tt>'''{{<font color=red>subst:</font>Your message<nowiki>}}</nowiki>'''</tt>. <tt><nowiki>{{subst:Your message}}</nowiki></tt> makes a copy of the message text and places it where you put the tag after you save an article (substitution).  Without "subst", the message will be loaded and put on the page every time you view it, a process known as [[transclusion]].
 
There are two major ways to include custom messages, <tt>'''<nowiki>{{Your message}}</nowiki>'''</tt> and <tt>'''{{<font color=red>subst:</font>Your message<nowiki>}}</nowiki>'''</tt>. <tt><nowiki>{{subst:Your message}}</nowiki></tt> makes a copy of the message text and places it where you put the tag after you save an article (substitution).  Without "subst", the message will be loaded and put on the page every time you view it, a process known as [[transclusion]].
Line 70: Line 70:
 
=== A caution about line breaks ===
 
=== A caution about line breaks ===
  
Note that some templates may accidentally cause extra linebreaks in the rendered articles. This is especially true of [[Centiare:Infobox templates]] and other template boxes that usually float on the right side of an article, since the additional lines will not be seen on the template page.
+
Note that some templates may accidentally cause extra linebreaks in the rendered articles. This is especially true of [[Help:Infobox templates]] and other template boxes that usually float on the right side of an article, since the additional lines will not be seen on the template page.
  
 
As a general guideline, avoid two break lines together in your template. These may "add up" with other breaklines in the article and be displayed as unwanted white space.
 
As a general guideline, avoid two break lines together in your template. These may "add up" with other breaklines in the article and be displayed as unwanted white space.

Latest revision as of 22:30, 27 December 2007

Templates are used to duplicate the same content across more than one page. You can change a template in one place and it will immediately propagate to the pages that use it.

Introduction

Templates often look like text boxes with a different background color from that of normal text. They are in the template namespace, i.e. they are defined in pages with "Template:" in front of the name.

Templates can accept template parameters which are then inserted into the output of the template.

Templates in the article namespace provide information to help readers. These can include navigation aids, or warnings that content is sub-standard. Templates that provide information only of service to editors belong on an article's talk page.

With the template [Help:namespace|]] it is possible to include the contents of a page in that namespace within a page in a different namespace, using double curly braces around the template title (for example, {{title}} would import Template:Title). This is used to:

  • place recurring messages (such as those to denote stubs, disambiguation pages, etc.) into articles in a consistent manner;
  • insert boilerplate messages for various issues like copyright violation, neutrality disputes, etc., using a simple shortcut command; and
  • create navigational templates and sidebars to link series of related articles together.
  • create infoboxes

Templates should not masquerade as article content in the main article namespace; instead, place the text directly into the article.

Templates should also not be used to create lists of links to other articles when a category or a See also list can perform the same function.

Template creation

To create a new custom message, simply create a page in the Template namespace, named "Template:", followed by a name for the message, that contains the text of the message. Names can now contain spaces and initial case is irrelevant. An alternate method is to create a link something like [[Template:mymessage]] on your user page or in the sandbox and then click on it. You may want to consider protecting the messages you create (if you have administrator privileges), but see the talk page for a discussion of this. Please list any custom messages you create on this page.

Usage

To add a template to the page, simply type the name of the template with two braces on each side. For example, to add Template:Infobox_Company to a page, type {{Infobox_Company}}.

If a template takes a number of parameters, it is suggested that the template be formatted as the following:

{{TemplateName
|      param = Param value
| parameter2 = Text
|   variable = Variable text
}}

Putting each parameter on a separate line and aligning them by the equals sign make it easier to read the wikicode.

Dynamic or subst

Main article: Help:Template substitution

There are two major ways to include custom messages, {{Your message}} and {{subst:Your message}}. {{subst:Your message}} makes a copy of the message text and places it where you put the tag after you save an article (substitution). Without "subst", the message will be loaded and put on the page every time you view it, a process known as transclusion.

In other words, when the message is updated, you do not need to update a page that uses it if you use {{Your message}}. As a guideline, short temporal messages that will be removed soon should be copied using subst (which has the advantage of showing the message in the wiki source), and standard notices that might remain on a page for months or forever should be transcluded for easy updating. (You should not use {{Your message}} for a message which contains any links which may change in the future. This method doesn't refresh "What links here" unless every article containing the {{Your message}} gets changed after the modification of the link in the message.)

If you need to edit the template message individually after you put it on your page, use subst. If you don't need to edit it, and would rather the message is automatically updated along with changes made to the template, don't use subst.

For an example how to substitute variables at the time of their inclusion see the subst magic section in Help:Variables.

Template documentation

A template can sometimes be difficult to use by only looking at the source of the template, so it's encouraged that you document your template.

There are two different ways to do this.

One alternative is to use <noinclude> to include a minor description direct into the template, for example:

'''This is a {{1}} article.'''<noinclude>
Place this template on any article that requires description. It takes one parameter, an 
adjective used to describe the article. For example, {{article-describe|bad}} produces the text, 
'''This is a bad article.'''
</noinclude>

Another alternative is to use the template talk page for documentation (preferred for templates with multiple parameters etc...). Using this approach, it's recommended to separate documentation and discussion, easiest by using level one sections to separate (this is an exception to the style guideline):

=Documentation=
usage etc...
=Discussion=
other discussion about the template

The easiest approach to accomplish the second approach is to type Template:Tls to the template talk space, that will insert standardized boilerplate text for the documentation.

A caution about line breaks

Note that some templates may accidentally cause extra linebreaks in the rendered articles. This is especially true of Help:Infobox templates and other template boxes that usually float on the right side of an article, since the additional lines will not be seen on the template page.

As a general guideline, avoid two break lines together in your template. These may "add up" with other breaklines in the article and be displayed as unwanted white space.

Sandbox for experiments

If you wish to experiment with templates (and not have your experiments deleted before you are done with them), you may do so in the Template sandbox. You may also use the templates X1, X2, X3, X4, X5, X6, X7, X8 and X9 for experimental purposes. To include a test template, use the form {{X1}} for template X1, {{X2}} for template X2, etc.