no image

Templates Lesson 3: Template Parameters

Privacy Level: Public (Green)
Date: [unknown] [unknown]
Location: [unknown]
Profile manager: Steven Harris private message [send private message]
This page has been accessed 177 times.

Template Lessons > Lesson 3

Scope

A template can contain parameters that give the template a special function. Parameters are identified by enclosure in three curly braces {{{ }}}. The values for these parameters can then be specified in the template when it is called from another page.

Parameters not only allow a user to customize the output of a template, but they may even be able to control which specific actions the template performs.

Named and Unnamed Parameters

Unnamed parameters are, as the name implies, parameters that do not have a specific name assigned to them. Unnamed parameters are numbered in the order in which the user inputs the information in the template when it is called. On the other hand, named parameters are parameters that have a specific name assigned to them, and those names must be used in order to pass information to the template.

As an example, let's say we would like to create Template:Welcome, where the end user can supply their own text:

Single Unnamed Parameters Single Named Parameters
Identified in the template code:
  Welcome to WikiTree! {{{1}}}
Identified in the template code:
  Welcome to WikiTree! {{{text}}}
Template usage:
  {{Welcome|I hope you have fun!}}
Template usage:
  {{Welcome|text=I hope you have fun!}}
Displays as:
  Welcome to WikiTree! I hope you have fun!
Displays as:
  Welcome to WikiTree! I hope you have fun!

While unnamed parameters can be faster for end users, it can also introduce some errors if the parameters are not used in the correct order as designed. For instance, let's say we would like to expand the above Template, where the end user can supply not only their own text, but can sign their name by adding another parameter:

Multiple Unnamed ParametersMultiple Named Parameters
Identified in the template code:
  Welcome to WikiTree! {{{1}}} Regards, {{{2}}}
Identified in the template code:
  Welcome to WikiTree! {{{text}}} Regards, {{{name}}}
Template usage:
  {{Welcome|I hope you have fun!|Bob Smith}}
Template usage:
  {{Welcome|text=I hope you have fun!|name=Bob Smith}}
Displays as:
  Welcome to WikiTree! I hope you have fun! Regards, Bob Smith
Displays as:
  Welcome to WikiTree! I hope you have fun! Regards, Bob Smith


Learning Exercises

Exercise 1 - Using your Sandbox, call the {{Absent}} sticker using the following examples:

{{Absent|10 Jun 2014|I expect to return 25 Dec 2014}}
{{Absent|I expect to return 25 Dec 2014|10 Jun 2014}}

How does the sticker react to each example? Does the order of unnamed parameters change the display of the template?


Exercise 2 - Using your Sandbox, call the {{Occupation}} sticker using the following examples:

{{Occupation|image=Swedish_Profession_Templates-3.jpg|text=was a shoemaker}}
{{Occupation|text=was a shoemaker|image=Swedish_Profession_Templates-3.jpg}}

How does the sticker react to each example? Does the order of unnamed parameters change the display of the template?


Continue to ⟶ Templates Lesson 4: Magic Words





Collaboration


Comments

Leave a message for others who see this profile.
There are no comments yet.
Login to post a comment.