1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-08 19:09:57 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/widgets/ParametersWidget.tid
jeremy@jermolene.com 32a6b6bb90 Docs updates
2022-09-09 12:05:08 +01:00

50 lines
2.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

caption: parameters
created: 20220909111836951
modified: 20220909111836951
tags: Widgets
title: ParametersWidget
type: text/vnd.tiddlywiki
<<.from-version "5.3.0">> The <<.wlink ParametersWidget>> widget is used within transcluded content to declare the parameters to be made available to the <<.wlink TranscludeWidget>> widget.
There are shortcuts for common scenarios that can often make it unnecessary to use the <<.wlink ParametersWidget>> widget directly:
* the `\parameters` [[pragma|Pragma]]
* the `\procedure` [[pragma|Pragma]] for declaring procedure
* the `\widgets` [[pragma|Pragma]] for declaring custom widgets
* the `_parameters` field of tiddlers containing [[Global Definitions]]
The <<.wlink ParametersWidget>> 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 <<.wlink ParametersWidget>> 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 |
|//{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 |
<<.note "Note the special treatment required for parameters names that start with a `$`; this can be avoided by using one of the pragmas">>
!! `$depth` Attribute
By default, the <<.wlink ParametersWidget>> 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. This is useful in some situations where an intervening transclusion prevents immediate access to desired parameters.
! Examples
Here the <<.wlink ParametersWidget>> widget is used to declare a parameter whose default value is transcluded from another tiddler.
<$macrocall $name='wikitext-example-without-html'
src="""\procedure mymacro
<$parameters name={{$:/SiteTitle}} age="21">
My name is <<name>> and my age is <<age>>.
</$parameters>
\end
<$transclude $variable="mymacro" age="19"/>"""/>