Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Help:Template
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Examples=== {{A note}} If you wish to experiment with any of these, you can use the [[Template:Template sandbox|template sandbox]] or your user page or sandbox. You can try out your template with [[Special:ExpandTemplates]]. An example of a very simple template can be found at [[Template:TM]], which expands to wikitext that places the trademark symbol (™), linked to the [[trademark]] article, at that point in the displayed page. A programmer would say that the template "returns" the trademark symbol link wikitext. Display [[Template:TM]] (by clicking on the foregoing link), then click on the "Edit" tab to see the template code (its page source). The active part of that code, which becomes the expansion of the template when it is transcluded, is the single link wikitext <code><nowiki>[[Trademark|™]]</nowiki></code>. The remainder of the page source is enclosed between {{xtag|noinclude}} tags, so it shows up when you display the template page itself but not when you display a page that calls the template. To transclude Template:TM onto another page (i.e., to use it on another page), type {{tlx|TM}} into the source of that page (the target page) and click {{Button|Show preview}}. The page will be displayed with the template call replaced by the expansion of the template, as if the wikitext actually contained <code><nowiki>[[Trademark|™]]</nowiki></code> at that point. The displayed page will therefore contain the wikilink "[[Trademark|™]]". For example, type <code>The trademark symbol is {{tl|TM}}</code> and you will see "The trademark symbol is {{TM}}" when previewing the page or after saving the change. The other way to use a template is to [[Help:Substitution|substitute]] it. If you type <code>The trademark symbol is {{tls|TM}}</code> and preview or save the page, you will see "The trademark symbol is [[Trademark|™]]" just as with the transclusion example above. But if you save the page and then look again at the saved page <em>source</em>,{{efn|There is no way to preview the effect on the page source of substitution without saving the page}} you will see <code>The trademark symbol is <nowiki>[[Trademark|™]]</nowiki></code>, because the template call was replaced by the expansion of the template when you saved the page. There is no ongoing connection to the template call; no one can tell by looking at the page source that you didn't just type <code>The trademark symbol is <nowiki>[[Trademark|™]]</nowiki></code> and if the {{tl|TM}} template changes (or ceases to exist), your page will continue to display as it does now. (In contrast, in the transclusion example above, if the {{tl|TM}} template subsequently changes, your page may then display differently). ===={{anchor|Parameters}} Examples with parameters==== An example of a template that takes parameters is the template {{tlx|about}}. Try typing {{tnull|about|how to use templates|how to use modules|Help:Lua}} in the sandbox—it will produce the following text: {{about|how to use templates|how to use modules|Help:Lua}} The template {{tlx|about}} uses three [[unnamed parameter]]s (also called positional parameters) in the example above, but you can call the same template with different numbers of parameters to give slightly different results, as explained in [[Template:About/doc|the template's documentation]]. For example, {{tnull|about||how to use modules|Help:Lua}}. Note the usage of an empty parameter—in this instance, the consecutive pipes mean that the first parameter specified is an empty string, which in this template will cause it to omit the initial "about" sentence. This produces: {{about||how to use modules|Help:Lua}} A simple example of a template that has named parameters is [[Template:Payoff matrix]], used to generate a 2-by-2 grid. For example: {{Markup|<nowiki>{{payoff matrix | UL = 5 | UR = 7 | DL = 2 | DR = 9 | Name = Example usage }}</nowiki>|{{payoff matrix | UL = 5 | UR = 7 | DL = 2 | DR = 9 | Name = Example usage }}}} See the [[Template:Payoff matrix|template page]] for more possibilities. Notice that the template is called here without specifying all its possible parameters, so undefined parameters are given default values.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)