Using the old deprecated macros, one can use text substitution to populate the attributes of an action widget. For example:
\define newTiddlerActionWidget(title: "My Tiddler", tags: "[[My Tag]]")
<$action-sendmessage
$message="tm-new-tiddler"
title="$title$"
tags="$tags$"
/>
\end
If testing this using something like <$button actions=<<newTiddlerActionWidget "Some Title">>>New Tiddler</$button>
and click the button, you get a draft of a new tiddler titled “Some Title” (using the parameter specified in the macro call) and tagged My Tag
(using the default parameter value).
However, I have found that this will not work if I use variable substitution in the macro instead (using <<__title__>>
and <<__tags__>>
instead of $title$
and $tags$
); it will have no tags and the TiddlyWiki-wide default “New Tiddler” title.
If I use a procedure, since macros are deprecated, I get the same result.
\procedure newTiddlerActionWidget(title: "My Tiddler", tags: "[[My Tag]]")
<$action-sendmessage
$message="tm-new-tiddler"
title=<<title>>
tags=<<tags>>
/>
\end
Since these parameters are needed in widget attributes, I figured I’d try the new attribute text substitution (note that the text substitution below isn’t a procedure thing but simply a widget attribute thing, using the procedure parameters as the variables):
\procedure newTiddlerActionWidget(title: "My Tiddler", tags: "[[My Tag]]")
<$action-sendmessage
$message="tm-new-tiddler"
title="$(title)$"
tags="$(tags)$"
/>
\end
But when I tried this, I literally got a new tiddler draft titled “$(title)$” and tagged $(tags)$
.
My initial conclusion was that TW wikifies the “actions” attribute of the button only once, and that the one-time wikification replaces the procedure or macro call with its contents, but doesn’t do any further processing or wikification of those contents, except for macro text substitution. I figured that unlike attribute text substitution within a procedure, macro text substitution occurs in the initial replacement of the macro call with the text of the macro.
But that’s not the reason either; at least some other things get further processed in both macros and procedures. For example:
\procedure newTiddlerActionWidget(title: "New Tagged Tiddler", tags: "[[My Tag]]")
<$action-sendmessage
$message="tm-new-tiddler"
title=<<title>>
tags=<<tags>>
timestamp=<<now "[UTC]YYYY0MM0DD0hh0mm0ss0XXX">>
/>
\end
When I click a button with the actions defined by that procedure, the timestamp
field comes out to the current time in the specified format. (The same holds true for a macro.)
Additionally, if I surround the button with a <$let>
widget defining values for title
and tags
, the variables defined by the $let widget are used. For example:
<$let title="Some Other Title" tags="[[Some Other Tag]]">
<$button actions=<<newTiddlerActionWidget "Some Title" "[[Some Tag]]">>>New Tiddler</$button>
</$let>
Then if I click the button, the new tiddler will not be titled “Some Title” but “Some Other Title”, and it will not be tagged Some Tag
but Some Other Tag
.
In other words, the <$action-sendmessage> widget cannot use procedure parameters! It can use variables and macros etc.–for example, the <<now>>
macro or variables defined in the <$let>
widget surrounding the button. But it cannot use the values in procedure or macro parameters (except text substitution of macro parameters).
Why is this??? I don’t understand it. I’m losing my mind.
(Of course, if I want such a parameterizable action widget, I can always just use variables and set them with some other widget such as <$let>
around whatever triggering widget I’m using… so it’s not like I need help on a solution… but I can’t understand why the behavior is the way it is.)
One other edit:
To demonstrate that not all widgets are like this:
\procedure testVariables(var1: "var1", var2: "var2") <$link to=<<var1>>><<var2>></$link>
<<testVariables "HelloThere" 'Link to "HelloThere" '>>
This produces a link to HelloThere
with link text Link to "HelloThere"
, as one might expect. Thus, the <$link>
widget can use the parameters of procedures.
I am not going to test all widgets to see if they can use procedure parameters, but my hunch is that the unexpected behavior is specifically for action widgets.