How do I clone a tiddler while giving it a new title?

I have created a new sidebar tab with a list of my template tiddlers that I use often. How would I clone a tiddler and give a new name?

I have tried:

<$button message="tm=new-tiddler" param=<<list-item>> title="new title">
clone template
</$button>

But, the title="new title" is being ignored as that was the documentation said to do here: https://tiddlywiki.com/#WidgetMessage%3A%20tm-new-tiddler

This is what I am using below:

<$list filter="[all[]prefix[$:/TTA/templates/]!suffix[-(backup)]]" variable="list-item">
	<div class="tc-sidebar-tab-open-item tc-sidebar-clone">
		<$button class="tta-sidebar-button" message="tm-new-tiddler" param=<<list-item>> title={{{ [<list-item>removeprefix[$:/TTA/templates/]addprefix[new ]] }}}>
			{{$:/core/images/clone-button}}
		</$button>
		<$button class="tc-sidebar-clone-link" message="tm-new-tiddler" param=<<list-item>> title={{{ [<list-item>removeprefix[$:/TTA/templates/]addprefix[new ]] }}}>
			<$text text={{{ [<list-item>removeprefix[$:/TTA/templates/]addsuffix[ template]] }}}/>
		</$button>
	</div>
</$list>
<$button actions="""
	<$action-sendmessage $message="tm-new-tiddler" $param=<<list-item>> title="new title" />
""">
clone template
</$button>
2 Likes

Thank you! Works as intended!

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

6 Likes

@EricShulman thanks for this nicely prepared instruction that really goes to the key issues.

Just for clarification;

Is it correct to say?

In fact this is the parameters of any actions referenced via the action=<<actions-macro>>, in addition to $action-sendmessage widgets.

Yes. That is correct. I was focusing on the example using $action-sendmessage, but this applies to any actions, not just “sendmessage”.

-e

1 Like