Parameterized Transclsuion: The Parameters Widget

One interesting new feature in TiddlyWiki 5.3.0 is the ParametersWidget and Parameters pragma. I like to ask developers and supper users to shed light on this amazing feature help us how to use it in a correct way.

References

I will also give some examples

Example i

I have a template tiddler called Parameters/template01 with below consents:

<$parameters name="Jeremy" age="21">
My name is <<name>> and my age is <<age>>.
</$parameters>

Then in another tiddler, I can use the above template like below:

This example uses [[Parameters/template01]].

* Example 
** <$transclude $tiddler="Parameters/template01" />

* Example i
** <$transclude $tiddler="Parameters/template01" age=33/>

* Example ii
** <$transclude $tiddler="Parameters/template01" name=Saq age=30/>

Which produces

This example uses Parameters/template01.

  • Example
    • My name is Jeremy and my age is 21.
  • Example i
    • My name is Jeremy and my age is 33.
  • Example ii
    • My name is Saq and my age is 30.

Remarks

  • Through transclusion you can pass the parameters value
  • You can use the default value
  • You also have all the features of transcluding by templates of classis transclusion

To give a try

2 Likes

This also works with your example

{{Parameters/template01|tony|N/A}}
  • But I can’t find this documented, but it is demonstrated somewhere.

Using the parameters widget in any tiddler with TiddlyWiki Script, work as an alternative to define, set, let, vars however can optionally be overridden on transclusion as you demonstrate.

There is also the $variables form of transclusion, I think we are only scratching the surface of the 5.3.0 release possibilities.

Or change the template to

<$parameters name=Jeremy age="21">
My name is <<name>> and my age is <<age>>.
This=<<thisTiddler>> by <<currentTiddler>>

</$parameters>

and transclude as follows

{{||Parameters/template01|tony|N/A}}
1 Like

Example ii: This example also uses the \parameters pragma. It is recommended to be used inside widgets and procedures, but this example demonstrates how to use \parameters pragma in a template.

The content of Parameters/template02 tiddler

\parameters (firstname:"Joe",lastname:"Blogs")

<$parameters name=Jeremy age="21">
My name is <<name>> and my age is <<age>>.
</$parameters>

* <<firstname>>
* <<lastname>>

Then in another tiddler we have

* Example i
** <$transclude $tiddler="Parameters/template02" $mode=block/>

* Example ii
** <$transclude $tiddler="Parameters/template02" age=33  firstname=Mohammad lastname=Parsi $mode=block/>

* Example iii
** <$transclude $tiddler="Parameters/template02" name=Saq age=30  $mode=block/>

which produces

  • Example i
    • My name is Jeremy and my age is 21.
      • Joe
      • Blogs
  • Example ii
    • My name is Jeremy and my age is 33.
      • Mohammad
      • Parsi
  • Example iii
    • My name is Saq and my age is 30.
      • Joe
      • Blogs

IMPORTANT It is recommended to pass parameters by name instead of position! See [BUG] The First Attribute of a Parameters Pragma is Overwritten when Is used Inside a Procedure · Issue #7458 · Jermolene/TiddlyWiki5 (github.com) for details.

Please submit a PR with some examples. I added few other doc tiddlers.