Cloning a Tiddler

236 views
Skip to first unread message

Mohammad

unread,
Feb 19, 2019, 3:49:21 AM2/19/19
to TiddlyWiki
How is it possible to clone a tiddler without navigation to it?

  1. use the tm-new-tiddler
    • issue: open the tiddler in the story river, not good for bulk cloning
  2. use the action action-createtiddler
    • issue: has to iterate over all fields and copy one by one to the new tiddler, performance issue not simple
What do you propose? Any better solution?



--Mohammad

TonyM

unread,
Feb 19, 2019, 4:12:59 AM2/19/19
to TiddlyWiki
Mohammad,

There is an option when creating a tiddler to get the title of the new tiddler without navigating to it. See $savetitle
https://tiddlywiki.com/#ActionCreateTiddlerWidget and the differences with https://tiddlywiki.com/#WidgetMessage%3A%20tm-new-tiddler

Regards
Tony

TonyM

unread,
Feb 19, 2019, 4:16:43 AM2/19/19
to TiddlyWiki
Mohammad,

I previously created a nested list that generated a single variable containing fieldname=value fieldname2="value 2" that provided all field=value pairs.

Regards
Tony

FrD

unread,
Feb 19, 2019, 4:33:53 AM2/19/19
to TiddlyWiki
Hi,

Have a look at :


Delete the part where you remove a field. The drawback is that you need to know the new title.

Regards

FrD

Mohammad

unread,
Feb 19, 2019, 6:14:17 AM2/19/19
to TiddlyWiki
Hi,
 Thanks FrD, the problem is it will overwrite the existing tiddlers. I am looking to see how to clone as Tony said in his post.

Cheers
Mohammad

Thomas Elmiger

unread,
Feb 19, 2019, 11:56:55 AM2/19/19
to TiddlyWiki
Hi Mohammad,

You could try to use your first option (tm-new-tiddler) followed by a tm-close-tiddler action.

Did you already try that?

Good luck,
Thomas

Mohammad

unread,
Feb 19, 2019, 12:04:50 PM2/19/19
to TiddlyWiki
Hi Thomas,
No I did not. I thought opening and closing toddler may cause flittering.
But I will try.
Cheers
Mohammad

Mark S.

unread,
Feb 19, 2019, 1:31:20 PM2/19/19
to TiddlyWiki
Per FrD

Create a unique title (possibly title plus date stamp).
Use action-setfield to create new tiddler with the new, unique title.

-- Mark

Mohammad

unread,
Feb 19, 2019, 2:03:46 PM2/19/19
to TiddlyWiki
Hi Thomas,
 This does not work


<$button> Do it
<$list filter="[range[1,10]]" variable=item>
<$action-sendmessage $message="tm-new-tiddler" title=<
<item>> tags="uu">
<$action-sendmessage $message="tm-close-tiddler" param=<
<item>>/>
</$list>
</$button>

Mohammad

unread,
Feb 19, 2019, 2:06:52 PM2/19/19
to TiddlyWiki
Hi Mark,
Yes, but I have to iterate over all fields. By the way I found something through this question that seems buggy

<$button> Do it
<$list filter="[range[1,10]]" variable=item>
<$action-sendmessage $message="tm-new-tiddler" title=<<item>> tags="uu">
</$list>
</$button>


No go to Advanced serach /Filter and type

[tag[uu]]


and click on the Delete button (trash bin)

All draft tiddlers remain open with no title, tgas, ....

What happened?

--Mohammad

Mohammad

unread,
Feb 19, 2019, 2:45:17 PM2/19/19
to TiddlyWiki
Seems this work to clone a tiddler batchwise

\define clone(newTid,Template)
<$action-createtiddler $basetitle=$newTid$ $savetitle="temp" />
<$list filter="[<__Template__>fields[]] -title" variable=fname >
<$set name="fval" tiddler=<<__Template__>> field=<<fname>> >
<$action-setfield $tiddler={{temp}} $field=<<fname>> $value=<<fval>> />
</$set>
</$list>
\end

Example

<$button>Clone me
<$list filter="[range[1,5]addprefix[a00]]">
<$macrocall $name=clone newTid=<<currentTiddler>> Template=testTemplate />
</$list>
</$button>


where testTemplate  is a sample tiddler with many fileds, tags, text has been cloned.


--Mohammad

Mark S.

unread,
Feb 19, 2019, 2:56:46 PM2/19/19
to TiddlyWiki
Why do you need to iterate the fields? When you make a clone by renaming the title, all the fields get cloned too. Or at least that's what happened in my test.

Thanks!
-- Mark

FrD

unread,
Feb 19, 2019, 3:04:27 PM2/19/19
to TiddlyWiki


Le mardi 19 février 2019 20:06:52 UTC+1, Mohammad a écrit :
Hi Mark,
Yes, but I have to iterate over all fields.

Hi,

No, you don't have to iterate over the fields ; it clones the template and gives the clone the title you pass.

Regards

FrD

Thomas Elmiger

unread,
Feb 19, 2019, 3:27:13 PM2/19/19
to TiddlyWiki
Mohammad, here’s a version that works.

Note: There seems to be a bug in the documentation of https://tiddlywiki.com/#WidgetMessage%3A%20tm-close-tiddler where param is a parameter instead of $param (?)

<$button> Do it
<$list filter="[range[1,3]]" variable="item">
<$action-sendmessage $message="tm-new-tiddler" title=<
<item>> tags="uu"/>
<$action-sendmessage $message="tm-close-tiddler" $param={{{[has[draft.of]field:draft.of
<item>]}}}/>
</$list>
</$button>

tm-new-tiddler also has a param where you can give a template.

The action-setfield method from Mark and FrD looks also interesting, but is maybe a bit less readable if you come back to it after a few years.

Good luck!
Thomas

@TiddlyTweeter

unread,
Feb 20, 2019, 5:08:57 AM2/20/19
to TiddlyWiki
I found the   action-setfield  method of silent cloning very interesting. I had absolutely no idea that it existed andcan't find this behaviour mentioned in docs.

I assume it works because cloning a title clones the tiddler in its context of running?

Is it a lucky side effect, or part of planned design?

Best wishes
Josiah

Mohammad

unread,
Feb 20, 2019, 5:56:23 AM2/20/19
to TiddlyWiki
Dear all,
 Thanks for all your help. I understood how cloning is possible and I hopw I can use it in TW-Commander.


Cheers
Mohammad
Reply all
Reply to author
Forward
0 new messages