This is a stripped-down version of a single section of Grok TiddlyWiki, optimized for fast loading and readability by search engines. Some features are missing.

For the full Grok TiddlyWiki experience, please visit the wiki version of this page.

Ex:SaveOptionalParameters

 28th September 2024 at 7:32pm

The $link widget has many optional parameters besides to and tooltip: as of the current version, aria-label, tabindex, draggable, tag, class, overrideClass, and any number of CSS data attributes and properties. Right now, we are ignoring these, possibly causing undesired effects. For instance, the following link should be rendered like an external link, but fails to do so:

<$link to="Tiddlers" class="tc-tiddlylink-external">
  Tiddlers (fake external)
</$link>

To prevent such lost parameters, we need to pass all the parameters we aren't explicitly changing through to the original $link widget. We can combine two features to achieve this: (1) the $names and $values parameters of $genesis, which let you set an arbitrary number of parameters by providing two filters that evaluate to a list of parameter names and a list of corresponding values, and (2) the $params parameter to a widget (or function or procedure), which provides a JSON-formatted collection of all the parameters passed to the widget, even those that weren't specified in the parameters list.

You'll need to know several new things to complete this task:

(1) The $parameters widget, which is a more verbose way of specifying the parameters of something to be transcluded (including a widget), is needed to use the $params attribute – we can't specify $params directly in the (parameter list) of the \widget pragma. The value of the $params attribute is the name of a variable into which the parameters are placed. Here's the syntax:

\widget $link(to, tooltip)
  <$parameters $params="params-var">
    ...here <<params-var>> is JSON containing all the params, and <<to>> and <<tooltip>> contain the values of those specific parameters
  </$parameters>
\end

(2) To get the base lists of parameter names and values, use the following functions:

\function .rest-names() [<params-var>jsonindexes[]]
\function .rest-values() [.rest-names[]] :map[<params-var>jsonget<currentTiddler>]

(3) When you call the $genesis widget, you're supposed to be able to override any values in the $names and $values lists by additionally supplying that parameter (so that we could add a new tooltip parameter here, and that one would be used), but due to a bug in TiddlyWiki, this doesn't currently work. Instead, override parameters directly within the $names and $values lists by using new filter runs at the end with the = prefix, something like this:

$names="[[...blablabla]] =[[tooltip]]"
$values="[[...blablabla]] =[[tooltipvalue]]"

Go to answer: Ex:SaveOptionalParameters/answer