created: 20230518124403282 modified: 20230518135109977 tags: ParametersWidget title: ParametersWidget (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. <$macrocall $name=".example" n="1" eg="""<$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. <$macrocall $name=".example" n="2" eg="""<$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. <$macrocall $name=".example" n="3" eg="""<$transclude $tiddler="Sample Tiddler Template" age=45 name="Jeremy Ruston" />"""/> In the simple form the above transclusion is equivalent to <$macrocall $name=".example" n="3.1" eg="""{{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 <<.wid transclude>> is recommended over simple form transclusion. # However, if parameter values are passed by position, parameters get assigned sequentially based on the order <<.wlink ParametersWidget>> widgets are discovered. ''Example iv'': Here the <<.wlink ParametersWidget>> widget is used to declare a parameter whose default value is transcluded from another tiddler. <$macrocall $name=".example" n="4" eg="""\procedure myproc() <$parameters name={{$:/SiteTitle}} age="21"> My name is <> and my age is <>. \end <$transclude $variable="myproc" age="19"/> """/> ''Example v'': Here the <<.wlink ParametersWidget>> widget is used in addition to other parameter declarations, because later parameters depend on the value of earlier parameters. Positional values are assigned sequentially. <$macrocall $name=".example" n="5" eg="""\procedure myproc(age: 22) <$parameters acceptable-age={{{ [divide[2]add[7]] }}} > If you're <>, you can date a <>-year-old and it's not weird. \end <> <> <> """ />