Editing
Help:Templates
(section)
Jump to navigation
Jump to search
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!
==Parameters== To enrich the mechanism of transclusion, MediaWiki allows parameters to be passed to a template when it is transcluded. Parameters allow the template to produce different contents or have different behaviors. Suppose you wish to insert a little thank you note in the [[Help:Talk pages|talk page]] of other users, such as: {{Thankyou|all your effort|Me}} The thank you note will have a reason (in this case, "all your effort") and a signature ("Me"). Your objective is that any user is able to thank any other user, for any reason whatsoever. So that the note will look similar everywhere it is used, you can define a template called [[Template:Thankyou]], for example. Although the note should look similar whenever a user thanks another user, its specific contents (i.e. the reason and the signature) will be different. For that reason, you should pass them as parameters. If we ignore the remaining elements to format the box and place the image, the core content of the template will be this: <pre><nowiki>'''A little thank you...''' for {{{1}}}. hugs, {{{2}}}</nowiki></pre> Notice the use of <code><nowiki>{{{1}}}</nowiki></code> and <code><nowiki>{{{2}}}</nowiki></code>. This is the way to identify, within templates, the parameters that will be passed in when the template is used. Note that, within the template, each parameter is surrounded by '''three''' braces: <code><nowiki>{{{ }}}</nowiki></code>. This is different from normal template name usage. When using the template on a page, you fill in the parameter values, separated by a "pipe" character (<code>|</code>). MediaWiki allows parameters to be passed to the template in three ways: Anonymously, Numbered, and Named. === Anonymous parameters === To pass in anonymous parameters, list the values of those parameters sequentially: <nowiki>{{Thankyou|all your effort|Me}}</nowiki> In this case, the <code><nowiki>{{Thankyou}}</nowiki></code> template receives parameters <code><nowiki>{{{1}}}=all your effort</nowiki></code> and <code><nowiki>{{{2}}}=Me</nowiki></code>, producing: {{Thankyou|all your effort|Me}} The order in which anonymous parameters are passed in is crucial to its behaviour. Reversing the order of the parameters, like so: <nowiki>{{Thankyou|Me|all your effort}}</nowiki> would produce this result: {{Thankyou|Me|all your effort}} '''Note:''' identifying parameters by order (with <code><nowiki>{{{1}}}</nowiki></code>, etc) works ''only'' with anonymous parameters. If your page identifies any parameter by number or name, as shown below, this method will no longer be available to the template which receives them. === Numbered parameters === To pass in parameters by number, identify each parameter when passing it: <nowiki>{{Thankyou|2=Me|1=your friendship}}</nowiki> This time, template <code><nowiki>{{Thankyou}}</nowiki></code> receives parameters <code><nowiki>{{{1}}}=your friendship</nowiki></code> and <code><nowiki>{{{2}}}=Me</nowiki></code>, though they have been supplied in inverse order, and produces: {{Thankyou|2=Me|1=your friendship}} === Named parameters === The third way of passing parameters is by name, instead of numbers. In this case, the template contents would be changed to: <pre><nowiki>'''A little thank you...''' for {{{reason}}}. hugs, {{{signature}}}</nowiki></pre> Within the template, we use <code><nowiki>{{{reason}}}</nowiki></code> and <code><nowiki>{{{signature}}}</nowiki></code> to identify each parameter, instead of a number. To pass these parameters by name, identify each parameter when passing it: <nowiki>{{Thankyou|signature=Me|reason=being who you are}}</nowiki> In this case, template <code><nowiki>{{Thankyou}}</nowiki></code> receives parameters <code><nowiki>{{{reason}}}=being who you are</nowiki></code> and <code><nowiki>{{{signature}}}=Me</nowiki></code> and produces: {{Thankyou|signature=Me|reason=being who you are}} The advantage of using named parameters in your template, besides also being flexible in the order parameters can be passed, is that it makes the template code much easier to understand if there are many parameters. === Default values === If you transclude a template that expects parameters, but do not provide them, in this way: <nowiki>{{Thankyou}}</nowiki> in the numbered parameters example above you would get the following: {{Thankyou}} Since no parameters were passed in, the template presents the parameters themselves, instead of their respective values. In these cases, it may be useful to define ''default'' values for the parameters, i.e. values that will be used if no value is passed in. For example, if the template contents are changed to: <pre><nowiki>'''A little thank you...''' for {{{reason|everything}}}. hugs, {{{signature|Me}}}</nowiki></pre> then <code><nowiki>{{{reason|everything}}}</nowiki></code> defines that if no parameter <code>{{{reason}}}</code> is provided, then the value <code>everything</code> will be used. Similarly, <code><nowiki>{{{signature|Me}}}</nowiki></code>, defaults parameter <code>{{{signature}}}</code> to value <code>Me</code>. Now, transcluding the template again without passing any parameter, results in the following: <!-- strictly speaking, this example is false, because the template call was changed to obtain the desired effect - but the effect is the same if the template is defined as described --> {{Thankyou|reason=everything|signature=Me}}
Summary:
Please note that all contributions to Fanra's EverQuest Wiki are considered to be released under the Creative Commons Attribution Share Alike (see
Project:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Help page
Discussion
English
Views
Read
Edit source
View history
More
Search
Main Menu
Main page
Sections
Classes and Races
Spells, Songs, Disciplines, and AAs
Items
Zones
NPCs
Quests
Raids
Tradeskills
User Interface
Tips and Guides
EQ Links
Wiki
Recent changes
Advanced search
Random page
Help
Contact Fanra
Tools
What links here
Related changes
Upload file
Special pages
Page information