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

Le samedi 11 août 2018 09:53:40 UTC+2, TonyM a écrit :
>
> 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
>
> On Saturday, 11 August 2018 17:40:33 UTC+10, FrD wrote:
>>
>> 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.
>>
>> Go to https://tiddlywiki.com/
>> 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
>>
>> Le samedi 11 août 2018 09:12:03 UTC+2, TonyM a écrit :
>>>
>>> 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
>>>
>>> On Friday, 3 August 2018 12:46:30 UTC+10, TonyM wrote:
>>>>
>>>> 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
>>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/320c6064-acfa-461e-90c8-0bf9429b23fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: generateNewTitle.js.json
Description: application/json

Reply via email to