Template:Template creation and usage
From Ece
See the template creation and usage page for more information on templates.
This page gives documentation on how to create and use Wiki templates. The text above this paragraph is the text included in a Wiki page when that page uses this template.
Contents |
Usage
To use this template, place the text {{Template creation and usage}} in your Wiki template. For example: {{Template creation and usage}} produces the following sentence:
See the template creation and usage page for more information on templates.
All templates should include this template to provide potential authors with a starting point for template documentation, preferably after the first sentence of the template's documentation. As an example of usage and placement, consider the text of the DigiKeyPart template:
[http://www.digikey.com/scripts/DkSearch/dksus.dll?PName?Name={{{1}}}&Site=US Digi-Key {{{1}}}]<noinclude> This template provides a link to a specific part on the Digi-Key web site, given the part number. {{Template creation and usage}} == Usage == Within a wiki page, place the fragment <code><nowiki>{{DigiKeyPart|part_num}}to place a link to part_num on the Digi-Key web site. For example:{{DigiKeyPart|QRD1114-ND}}</nowiki></code> produces {{DigiKeyPart|QRD1114-ND}}. </noinclude>
Advanced usage
To suppress inclusion of the [[Category:Templates]] tag discussed in the the documentation section, use the syntax {{Template creation and usage|nocategory}}. The intended use of this feature is on the Category:Templates page, where inclusion of the [[Category:Templates]] tag creates an (unwanted, in this case) subcategory tag (see subcategories).
Templates
A template (termed a transclusion) is a simple macro facility for Wiki pages. See the full documentation or a quick start guide for more detailed information.
Creation and usage
To create a template, simply create a new Wiki page preceded by Template:; for example, this template page is titled Template:Template creation and usage. To use a template in a Wiki page, enclose the template's name in double curly braces; the usage section above gives an example.
Editing
When editing a template, the "Show preview" button can be used to see changes made in the documentation to a template; however, the text actually included by the template (even if used in the documentation section) will not be updated until the "Save page" button is clicked. Therefore, when editing before the <noinclude> tag, always click "Save page" to see the results of your edit; clicking "Show preview" will, as a preview, show the results of the last saved template, not the preview you're seeing.
When editing a Wiki page which includes a template, all templates used on that page will be listed just below the Save page, Show preview, and Show changes buttons.
Parameters
In a template, {{{1}}} references the first parameter passed, {{{2}}} the second parameter, and so on. To pass parameters to a template, separate them by vertical bars: {{DemoTemplate|hello|world}} in a Wiki page means that in the (nonexistent) Template:DemoTemplate, {{{1}}} is hello and {{{2}}} is world. As a second example, {{DigiKeyPart|QRD1114-ND}} references the DigiKeyPart template, which takes one parameter (here, QRD1114-ND) and produces a link to the Digi-Key web site page for that part: Digi-Key QRD1114-ND. More sophisticated usage is also possible.
Documentation
To document a template, surround your template's documentation with the <noinclude> and </noinclude> tags. Inclusion of this template automatically adds the statement [[Category:Templates]] to enable Wiki authors to easily obtain a list of templates. Place the <noinclude> tag immediately after the end of your template text, not on the next line. Placing the template on the next line means that the extra newline is included as part of the template, which can make paragraphs break unexpectedly. For example, this template begins with the code
See the [[Template:Template creation and usage|template creation and usage page]]...<noinclude>
This page gives documentation...
Therefore, this template can be included using {{Template creation and usage}} which produces the following sentence: See the template creation and usage page for more information on templates.
The paragraph continues after this template inclusion. As a counterexample, if the <noinclude> tag is incorrectly placed, as in the Incorrect template noinclude placement template, the resulting sentence causes an unexpected paragraph break:
The incorrect template noinclude placement page injects an unwanted newline by placing the <noinclude> tag on the line after the template text.
This sentence is therefore incorrectly placed in a new paragraph.




