Delete a field on a newly "cloned" tiddler

360 views
Skip to first unread message

TonyM

unread,
Aug 2, 2018, 10:46:30 PM8/2/18
to TiddlyWiki
Folks/Team,

I am creating a tool to create tiddlers from template tiddlers and will share today (if I resolve this).

However to do so I am using the following to clone the tiddler to a new tiddler name eg "task 1" and open for edit (which the user then modifies)

\whitespace trim
<$button message="tm-new-tiddler" param=<<currentTiddler>> tooltip="Clone this 'template'" aria-label="Clone this 'template'" class=<<tv-config-toolbar-class>> >
<$action-setfield $field=template-source $value=<<currentTiddler>>/>
<$action-deletefield $field=tiddler-template-caption/
>
{{$:/core/images/clone-button}}
</$button>

  • I identify which tiddlers are templates by the existence of the field tiddler-template-caption
  • During the clone which works perfectly the tiddler-template-caption also gets cloned
  • Unfortunately this means the new tiddlers now appear in the list of tiddler templates
  • In the above code <$action-deletefield $field=tiddler-template-caption/> deletes the field from the template tiddler not the new one.
  • How can I delete this field from the new tiddler with the yet to be determined name?
I believe I need to use message="tm-new-tiddler" param=<<currentTiddler>> rather than ActionCreateTiddlerWidget to clone the tiddler, where I would use the $savetitle.
I want the clone to work regardless of the fields and their content so I do not want to explicitly create the fields, I just want them to come from the template tiddler except for tiddler-template-caption.

Note: <$action-setfield $field=template-source $value=<<currentTiddler>>/> updates the template tiddler before the clone, this saves the user doing it.

How can I trigger <$action-deletefield $field=tiddler-template-caption/> on the new tiddler after it is named/created without an additional "trigger"

Thanks
Tony

TonyM

unread,
Aug 3, 2018, 12:36:04 AM8/3/18
to TiddlyWiki
Folks,

It would be good to answer this, especially if it was a "clean" and uncomplicated solution, however I have decided to flag template tiddlers using a method that does not get cloned ie no field, text or tag. In this case I am creating a subtiddler currenttiddler/template to indicate template tiddlers.

Regards
Tony

FrD

unread,
Aug 3, 2018, 3:04:23 AM8/3/18
to TiddlyWiki
Hi,

I've not written the code so it's not tested.

Perhaps the list of actions when you click the button could be :

- Remove the field from the template tiddler,
- clone the template tiddler
- add back the field to the template tiddler.

Regards

FrD

TonyM

unread,
Aug 3, 2018, 5:14:20 AM8/3/18
to TiddlyWiki
Frd

Thanks, I have used the work around to indicate template tiddlers by creating a matching tiddler templatename/template

In someways this may be better because the templatetiddler is now totaly cloned.

Regards
Tony

Mark S.

unread,
Aug 3, 2018, 10:47:02 AM8/3/18
to TiddlyWiki
I've tried an idea of my own and FrD's suggestion. The problem is, that once the tm-new-tiddler message is sent the current macro stops. So you can't do any clean-up back in the original macro.

Here's the code I tried using FrD's approach. The last setfield never gets run, even though it's simple text:

\whitespace trim
<$button tooltip="Clone this 'template'" aria-label="Clone this 'template'" class=<<tv-config-toolbar-class>> >{{$:/core/images/clone-button}}
<$vars tiddler-template-caption={{!!tiddler-template-caption}}>
<$action-deletefield $field="tiddler-template-caption"/>
<$action-setfield $field=template-source $value=<<currentTiddler>>/>
<$action-sendmessage $message="tm-new-tiddler" $param=<<currentTiddler>>  >
<$action-setfield $field="tiddler-template-caption"  $value=<<tiddler-template-caption>>/
>
<$action-setfield $field="do-i-happen"  $value="Important stuff"/>
</$vars>
</
$button>Enter code here...

The sendmessage pre-empts the rest of the code. I think you're stuck with using ActionCreateTiddler. But it shouldn't be that hard to cycle through all the fields and insert them into the new tiddler.

-- Mark

TonyM

unread,
Aug 3, 2018, 11:33:30 PM8/3/18
to TiddlyWiki
Mark,

As I posted I am happy to use the existence of a /template subtiddler because I can simply use a custom clone button. In fact I can see being able store additional info about the template or even listing the resulting tiddlers.

However I have thought of allowing check boxes on each field of one tiddler to copy or append to a target tiddler. Similer to how you suggest.

Regards
Tony

FrD

unread,
Aug 4, 2018, 3:03:08 AM8/4/18
to TiddlyWiki
Hi Tony,

Could you elaborate a bit about your solution and the use of a "subtiddler" ? This word seems to relate only to plugin tiddlers on https://tiddlywiki.com/. But I think you give it another meaning here and use it for something else.

Regards

FrD

TonyM

unread,
Aug 4, 2018, 4:34:20 AM8/4/18
to TiddlyWiki
Frd

I am using sub to suggest subordinate. Using the /template name after the tiddlername.

Tiddlername (actual template)
Tiddlername/template existing means tiddlername is a template.

Thus every tiddler with suffix[/template] says there is a template tiddler called removesuffix[/template]

When I clone templatename to templateinstance the subtiddler is not cloned and I do not need to modify the new tiddler

Regards
Tony

FrD

unread,
Aug 4, 2018, 4:45:41 AM8/4/18
to TiddlyWiki
H Tony,

I see. thanks for your explanation.

Regards.

FrD

TonyM

unread,
Aug 4, 2018, 4:50:15 AM8/4/18
to TiddlyWiki
Welcome

TonyM

unread,
Aug 11, 2018, 3:12:03 AM8/11/18
to TiddlyWiki
Mark,

Just to clarify, the "idea of [your] own and FrD's suggestion" just did not work?

I was relay smart because I decided to use a subtiddler such as task/template to indicate it was a template tiddler so task no longer held the removeme field and would not be cloned. This is a good idea but somewhere I decided this was a useful tip for creating templates for subTiddlers, and I returned it the above method only to be reminded it does not work again.


I am using the following to clone tiddlers I am using as templates;

<$button message="tm-new-tiddler" param=<<currentTiddler>> tooltip="Clone this 'template'" aria-label="Clone this 'template'" class=<<tv-config-toolbar-class>> >
<$action-setfield $field=template-source $value=<
<currentTiddler>
>/>
{{$:/PSaT/newTiddler/icon.svg}}
</$button>

So to restate the problem

This works nicely except I have to remove a field from the new Tiddler eg removeme
<$action-deletefield $field=removeme/>

Unfortunately if I use this in the above tiddler it removes the field from the source tiddler before the cloning.

As Mark suggested I may need resort to the ActionCreateTiddler so a Final call to see if anyone knows a workaround or has build a clone tool using ActionCreateTiddler?

Regards
Tony

FrD

unread,
Aug 11, 2018, 3:40:33 AM8/11/18
to TiddlyWiki
Hi TonyM,

Finally I found a way to do what you want. The drawback is that you need to know in advance the name of the tiddler you want to create.

Create a tiddler, for instance "testtemplate" with a tag ("MyTag"), some text and two fields : field1 and field2.
Create a tiddler, say "testcreate" with this code inside :

\define actions()
<$action-setfield $tiddler="testtemplate" $field="title" $value="MyNewTiddler" />
<$action-deletefield $tiddler="MyNewTiddler" $field="field2" />
\end

<$button actions=<<actions>>>
Create and remove field
</$button>

When you click the button, testtemplate is cloned (without being deleted) and field2 is removed from the cloned tiddler.
I think it's a convoluted way to use action-setfield and probably not the way it was intended to be used. But it seems to work.

Regards

FrD

TonyM

unread,
Aug 11, 2018, 3:53:40 AM8/11/18
to TiddlyWiki
Frd,

Thanks for your effort. Unfortunately I do not know the name before hand as I am cloning to create multiple instances of say tasks. They may be renamed or named task 1 task 2 etc...

This is a messy part of the available code.

So I am currentlt working on a copy selected fields to a new tiddler, which does create a new tiddler, but does not include the increment of duplicate tiddler names.

Arrrrgh, I can't win.

Perhaps I determine the new name myself and make it unique. This will be easier in the next release with the range operator.

Regards
Tony

FrD

unread,
Aug 11, 2018, 4:14:27 AM8/11/18
to TiddlyWiki
Hi TonyM,

There is a function in the core that generates a new title based on a given title (from task, it generates task 1, task 2, ...).
I've wrapped it in a js macro. You could try it. Import save and reload (in a test wiki or in a copy of your wiki !!!)

Just enter <<generateNewTitle "task">> or <<generateNewTitle "my favorite tiddler">>

Be careful with your data, try it on a copy.

Regards

FrD
generateNewTitle.js.json

TonyM

unread,
Aug 11, 2018, 9:43:33 AM8/11/18
to TiddlyWiki
Thanks Frd,

I will try it on sunday morning in around 10 to 11 hours.

I appreciate your help.

I must remember to document the final solution well because have wasted too much time on this even although I have learned some new things.

Regards
Tony

Mark S.

unread,
Aug 11, 2018, 2:56:19 PM8/11/18
to TiddlyWiki
This code is deceptively short, but it appears to do what you want:

\define catvalue() <$text text="""$(value2)$"""/>
\define fieldsvalues()
<$list filter="[all[current]fields[]] -[[tiddler-template-caption]] -[[text]]" variable="field"><$set name="value2" tiddler=<<currentTiddler>> field=<<field>> emptyValue=""><<field>>="<<catvalue>>" </$set> </$list>
\end
\define buttonactions() <$action-createtiddler $basetitle={{!!title}} $(attribs)$ text={{!!text}} />

<$wikify name="attribs" text=<<fieldsvalues>> >

<$button actions=<<buttonactions>>>Create clone
</$button>
</
$wikify>


I say deceptively because of all the wrong paths I went down before getting to it. It turns out that actioncreatetiddlerwidget has this weird thing that when you attempt to add fields to a just-created tiddler it makes a perfect clone ---- but wipes out the original! If real, that seems like a bug to me. So that path didn't work.

You'll be happy to know that part of this solution requires the wikify-a-list trick you demonstrated in another thread. Note that the text field is handled separately in order to avoid recursion.

This code needs to be "remembered" or stored somewhere, but not sure where.

HTH
-- Mark

TonyM

unread,
Aug 11, 2018, 9:15:26 PM8/11/18
to TiddlyWiki
Mark,

Great work, I had a hunch it could be done, and you got there 1st, "good on ya".

It is quite elegant, and I will re-engineer it for a global macro and named templates. Thanks very much.

I will keep it in my own repository and when I get around to building a community website, I will put it there however I think we can take this and modularise it differently.

What interests me is, if you include text in the <<fieldsvalues>> you have actually stored a tiddler in a field.  This allows us to store multiple tiddlers in one tiddler using its fields, or in a data tiddler (Aside from JSON files) and generate tiddlers from these in addition to cloning.

By providing $(attribs)$ to the buttonactions action-createtiddler we can leverage its $basetitle $savetitle and $timestamp so we can also provide the naming standard, get the title of the resultant tiddler and decide if it is time stamped as a clone or a new tiddler.

If we can generalise this effectively it makes a number of otherwise difficult things quite easy. See the inspiration that has followed below.

I am thinking of the following macros, 
  1. One to pack the current or named tiddler into a "parametised tiddler" including or excluding details as desired. Field or variable.
  2. One to unpack (or create a tiddler) from a "parametised tiddler" to a new tiddler including or excluding details as desired
    The following use the 1st & 2nd or will be options of them
  3. One to do both 1 and 2 at the same time (as we have discussed in this thread)
  4. One to unpack a "parametised tiddler" to "the current" tiddler including or excluding details as desired
  5. One to do both 1 and 4 at the same time (add/replaces fields from another tiddler)
You have inspired me to think of then using the above to support,
  • Archiving multiple tiddlers in one (packing tiddlers)
  • Provide an unpack as well Generate a set of different tiddlers from one tiddler
  • Making a copy of a tiddler inside one of its own fields
  • Creating a tiddler with its own unpack button
  • Creating a tiddler than can generate multiple sets of tiddlers with unique names eg; A New Project may have 5 tiddlers 
    • View all project items
    • Create that projects items
    • Edit a projects items details
    • etc..
  • Using a stored macro tiddler and generating a customised macro tiddler with custom settings.
  • Using a set of packed tiddlers for Wizards, demos, templated processes etc...
  • and more
I love a good algorithium

Regards
Tony

TonyM

unread,
Aug 11, 2018, 9:17:39 PM8/11/18
to TiddlyWiki
Frd,

Thanks for that. I can use Marks answer for this issue, but your utility will most likely assist in some of the advanced solutions I suggest in my reply to Marks last comment.

Generate NewTitle sounds like something that should be more available to tiddlywiki users.

Lovely
Regards
Tony

TonyM

unread,
Aug 12, 2018, 1:03:37 AM8/12/18
to TiddlyWiki
Folks,

With thanks to all and in this case mostly Mark S. My working solution is as follows

\define fieldname-value() <$text text="""$(fieldname-value-temp)$"""/>
\define fieldsvalues()
<$list filter="[all[current]fields[]] -[[tiddler-template-caption]] -[[text]] -[[title]] -[[created]] -[[modified]] -[[tiddler-template-caption]]" variable="field"><$set name="fieldname-value-temp" tiddler=<<currentTiddler>> field=<<field>> emptyValue=""><<field>>="<<fieldname-value>>" </$set> </$list>
\end
\define clone-current-actions()
<$action-createtiddler $basetitle={{!!title}} $savetitle="$:/temp/clone-current-title" $(attribs)$ text={{!!text}} />
<$action-navigate $to={{$:/temp/clone-current-title}}/>
\end
\define clone-template-actions()
<$action-createtiddler $basetitle={{!!instance-of}} $savetitle="$:/temp/clone-template-title" $(attribs)$ text={{!!text}} />
<$action-navigate $to={{$:/temp/clone-template-title}}/>
\end
\define clone-tiddler(tiddlername)
<$set name=tiddlername value="$tiddlername$" emptyValue=<<currentTiddler>> >
<$tiddler tiddler=<<tiddlername>> >

<$wikify name="attribs" text=<<fieldsvalues>> >
<$button actions=<<clone-current-actions>>class=<<tv-config-toolbar-class>> >Clone
</
$button>
</$wikify>
</
$tiddler>
</$set>
\end
\define new-template-instance(tiddlername,tags)
<$set name=tiddlername value="$tiddlername$" emptyValue=<<currentTiddler>> >
<$tiddler tiddler=<<tiddlername>> >

<$wikify name="attribs" text=<<fieldsvalues>> >
<$button actions=<<clone-template-actions>> class=<<tv-config-toolbar-class>> >New Instance
<$action-sendmessage $message="tm-edit-tiddler" $param={{$:/temp/clone-template-title}}/>
</
$button>
</$wikify>
</
$tiddler>
</$set>
\end

;Named tiddler

New Order<<clone-tiddler "$:/New order/template">> Clone

New Order<<new-template-instance "$:/New order/template">> Template

;On current tiddler

Clone this<<clone-tiddler>> 

Template this<<new-template-instance>> Only works if the current tiddler has an "instance-of" field with a basetitle

I will be building this into a Tiddler Template solution and aim to share that.

I altered same names to help me understand marks code. See the macro invocations at the bottom
  • clone-tiddler simply copies the tiddler to a new tiddler with the name iterated, with the exception of some fields. But all tags and the text.
  • new-template-instance does the same as clone but gets the new tiddler name from instance-of field (usually in a template tiddler) and has a different save title.
  • Both record the source tiddler in the new one
I hope this helps someone!

Tony

TonyM

unread,
Aug 12, 2018, 3:36:10 AM8/12/18
to tiddl...@googlegroups.com
Folks,

Because it related to work here I will share this with you first. Publish later.

The attached json bundle contains the "new from template tiddler" tools. On installation you will get a "new" sidebar tab that will lead you to all the information you need. This is not a plugin so no reload required.

Apart from a few macros you can use in any tiddler, or inside a list on the current tiddler there is a simple manager and a view template button that allows you to flag a tiddler as a template then simply create new instances of it via a dropdown list of templates.

Let me know if you have any problems or the information is not enough.

I see this as being a rapid development method to build standard tiddlers with the text fields and content such as a standard task field, then quickly create as many tasks as you want.

To list such tiddlers you could list those with a tag or field you placed on the template or all those with the tiddler-source field equal to the template tiddler. It is wise to make the template tiddlers system tiddlers so they do not appear in basic lists.

Please enjoy and providefeedback

Tony


new-tiddler-from-template.bundle.json
Reply all
Reply to author
Forward
0 new messages