There is more to the $parameters widget than first meets the eye

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.

3 Likes

Nice tip!
From a practical point of view, I would use Parameters in tiddler/procedure where it is semantic.
It seems one can send a variable number of parameters for the above example, but I am not sure how they can be used!

Thanks for sharing this. I am finding it quite useful. ~~ Hans

It has being designed to support parameters to transclusions as well so don’t limit the scope of its use.

If you write a procedure that calls a procedure you can pass additional parameters through that you need note code.

To make use of it you can use the variables that are set or write wikitext to parse the Params string.

I would also not write off using it “off label” as well, because it’s easy to later move code into a procedure with parameters and with almost no change.