New in v5.3.0 The $parameters
widget is used within transcluded content to declare the parameters to be made available to the $transclude
widget.
There are shortcuts for common scenarios that can often make it unnecessary to use the $parameters
widget directly:
- the Pragma: \parameters
- the Pragma: \procedure for declaring procedure
- the Pragma: \widget for declaring custom widgets
The $parameters
widget must be used directly in the following situations:
- When the default value of a parameter must be computed dynamically
- When the
$depth
attribute is used to retrieve parameters from a parent transclusion (see below)
Content and Attributes
The content of the $parameters
widget is the scope within which the values of the parameters can be accessed as ordinary variables.
Attribute | Description |
---|---|
$depth | The index of the parent transclusion from which to obtain the parameters (defaults to 1). See below |
$parseMode | Optional name of a variable in which is made available the parse mode of the content of the parent transclusion (the parse mode can be "inline" or "block") |
$parseTreeNodes | Optional name of a variable in which is made available the JSON representation of the parse tree nodes contained within the parent transclusion |
$slotFillParseTreeNodes | Optional name of a variable in which is made available the JSON representation of the parse tree nodes corresponding to each fill widget contained within the parent transclusion (as an object where the keys are the slot names and the values are the parse tree nodes) |
$params | Optional name of a variable in which is made available the JSON representation of the parameters passed to the parent transclusion (as an object where the keys are the parameter names and the values are the coresponding values) |
{attributes not starting with $} | Any attributes that do not start with a dollar are used as parameters, with the value specifying the default to be used for missing parameters |
{other attributes starting with $} | Other attributes starting with a single dollar sign are reserved for future use |
{attributes starting with $$} | Attributes starting with two dollar signs are used as parameters to the transclusion, but with the name changed to use a single dollar sign. The value specifies the default to be used for missing parameters |
$depth
Attribute
By default, the $parameters
widget retrieves parameters from the immediate parent transclusion. The $depth
attribute permits access to the parameters of parent transclusions by specifying an index to the parent to be inspected ("1" is the immediate parent, "2" is the parent of that parent, etc.). This is useful in some situations where an intervening transclusion prevents immediate access to desired parameters.
$parseMode
, $parseTreeNodes
, $slotFillParseTreeNodes
and $params
Attributes
These attributes provide low level access to the contents of the transcluding widget:
- The
$params
attribute provides access to the raw parameters provided to the transcluding widget. Represented in JSON as an object with keys of the parameter names and values of the corresponding parameter values - The
$parseMode
attribute containsblock
orinline
to indicate whether the contents was parsed in block or inline mode - The
$parseTreeNodes
attribute provides access to the raw parse tree nodes that represent the contents of the transcluding widget. Represented in JSON as an array of parse tree nodes - The
$slotFillParseTreeNodes
attribute provides access to the raw parse tree nodes corresponding to the filled slots within the contents of the transcluding widget. Represented in JSON as an object with keys of the slot name and values being an array of parse tree nodes
Examples
Example i: Shows transclusion of Sample Tiddler Template. The template tiddler has two parameters name
and age
and here their default values are used.
<$transclude $tiddler="Sample Tiddler Template" />
Example ii: Shows, another transclusion of Sample Tiddler Template, here the value of age
is passed, but name
uses its default value.
<$transclude $tiddler="Sample Tiddler Template" age=33/>
Example iii: Shows, another transclusion of Sample Tiddler Template, here the value of both name
and age
are passed.
<$transclude $tiddler="Sample Tiddler Template" age=45 name="Jeremy Ruston" />
In the simple form the above transclusion is equivalent to
{{Sample Tiddler Template|Jeremy Ruston|45}}
In this simple form, parameters passed by position not by name. So the first value is passed to the first parameter, here name
and the second value is passed to the second parameter, here age
.
Remarks
- Passing parameter by name is good practice and is recommended for clarity. So for parameterized transclusions, the use of
$transclude
is recommended over simple form transclusion. - When passing parameters value by position, you cannot pass the second parameter while the first one has not been passed.
Example iv: Here the $parameters
widget is used to declare a parameter whose default value is transcluded from another tiddler.
\procedure myproc()
<$parameters name={{$:/SiteTitle}} age="21">
My name is <<name>> and my age is <<age>>.
</$parameters>
\end
<$transclude $variable="myproc" age="19"/>