Inspired by How to use parameter widget to define variables in a procedure instead of let widget
I will Just add that contrary to previous comments, before I think the above thread was split by @pmario, the parameters widget can be used stand alone;
Place this in the “Stand alone Parameters widget” tiddler.
<$parameters name={{$:/SiteTitle}} age="21" $params=allparams>
My name is <<name>> and my age is <<age>>.
All "<<allparams>>"
</$parameters>
When using it this way it works like the $let widget and sets the variables, but since it is not called with parameters the allparams variable is {}
empty.
However the parameters widget does work when when you transclude something;
{{Stand alone Parameters widget|a|b}}
Result: My name is a and my age is b. All "{"0":"a","1":"b"}"
Or using the new transclude widget form
<$transclude $tiddler="Stand alone Parameters widget" name="alt-name" />
Result: My name is alt-name and my age is 21. All "{"name":"alt-name"}"
Note you can’t have unnamed parameters that are automatically assigned to 0, 1, 2 etc… when using this long form, however;
A variable without a value will be assigned true
<$transclude $tiddler="Stand alone Parameters widget" open/>
Result: My name is TiddlyWiki and my age is 21. All "{"open":"true"}"
To access parameters such as unnamed ones in the params variable you can parse the params as a JSON string using JSONget and JSONtype.
- This allows you to write transclusions/procedures with an indeterminant number of parameters, which is a big improvement on prior to the $parameters widget.
There is more, for example you can use params defined in the \procedure name(p1 p2)
at the same time as using the parameters widget but you need to understand the order of precedence.