Some guidance on sending messages from `$button` widgets:
The message and param parameters of a $button widget is the original method of using a $button to trigger a message.
With this method, the $buttonwidget ONLY handles message=... and param=..., and doesn’t allow use of other parameters that the specific message may need (e.g., using title=... with the tm-new-tiddler message.)
As the TWCore has evolved over the years, newer and more robust methods of sending messages have been added…
-
Using the $action-sendmessage widget within the body content of the $button allows you to specify other message parameters such as title=... with the tm-new-tiddler message.
Note that a limitiation of this method is that the $action-sendmessage parameters are parsed when the $button is rendered, even though the $action-sendmessage is only triggered when the $button is pressed.
Most of the time, this isn’t a problem. However, sometimes parameter values really need to be parsed only when the $button widget is actually pressed (e.g., title=<<now "0hh0mm0ss0XXX">>) so that their values will accurately reflect the current state of things.
-
To address this limitation (and improve performance in general), another method of triggering messages from $button widgets was added to the TWCore: the actions="""...""" parameter.
This method allows you to defer the parsing of parameters of the $action-sendmessage widgets until the $button is actually pressed so that parameters like that shown above are properly evaluated.
Note that the actions="""...""" method also allows you to put the actions into a separate macro definition instead of using the """...""" syntax to specify the actions to perform.
This lets you use more complex, re-usable actions with more readable code like this:
\define myButtonActions(format:"0hh0mm0ss0XXX")
<$let newTitle=<<now "$format$">>>
<$action-sendmessage $message=`tm-new-tiddler` $param="myTemplate" title=<<newTitle>>/>
</$let>
\end
<$button actions=<<myButtonActions>>>
create a new timestamped tiddler
</$button>
OR
<$button actions=<<myButtonActions "YYYY0MM0DD">>>
create a new datestamped tiddler
</$button>
enjoy,
-e