Fields added automatically to tiddlers created by default new button?

Hi everyone

In the control panel there are ways to specify title and tags of new tiddlers. I am wondering if there is a way to specify fields that should exist when I create a new tiddlers created by the default PageControls new tiddler button.

Take a look at the shadow tiddler, $:/core/ui/Actions/new-tiddler, which contains:

\define get-tags() $(textFieldTags)$ $(tagsFieldTags)$
<$vars textFieldTags={{$:/config/NewTiddler/Tags}} tagsFieldTags={{$:/config/NewTiddler/Tags!!tags}}>
<$action-sendmessage $message="tm-new-tiddler" tags=<<get-tags>>/>
</$vars>

As you can see, the default tags are defined by the contents of $:/config/NewTiddler/Tags, and uses the values contained in both the text field AND the tags field of that tiddler.

Then, the new tiddler is created by sending the tm-new-tiddler message. The documentation for that message indicates that you can provide additional fields in the message, and those fields will be automatically defined when the message is processed.

So, if you modify the tm-new-tiddler message shown above like this:

<$action-sendmessage $message="tm-new-tiddler" $param="$:/config/NewTiddler/Template"
tags=<<get-tags>> foo="something" bar="" mumble=""/>

Then, when you press the sidebar “+” button, it will create a new tiddler with the foo, bar, and mumble fields, where foo has a default value of “something”, and the other fields are blank by default.

Alternatively, you could replace the <$action-sendmessage $message="tm-new-tiddler"... /> message with these two action widgets:

<$action-createtiddler $basetitle={{$:/language/DefaultNewTiddlerTitle}}
$savetitle="$:/temp/NewTiddler/Title" $template="$:/config/NewTiddler/Template"
tags=<<get-tags>> />
<$action-sendmessage $message="tm-edit-tiddler" $param={{$:/temp/NewTiddler/Title}} />

The $action-createtiddler widget will create a new tiddler, using $basetitle={{$:/language/DefaultNewTiddlerTitle}} to auto-number titles named “New Tiddler”, “New Tiddler 1”, etc., and also add any fields defined in $:/config/NewTiddler/Template, plus whatever tags are specified via the $:/ControlPanel settings.

Note that, by default, $action-createtiddler does NOT open the newly created tiddler. However, we can use $savetitle="$:/temp/NewTiddler/Title" to store the title of the newly created tiddler, which is then used by the subsequent tm-edit-tiddler message to immediately open that tiddler for editing, just as the tm-new-tiddler message does.

-e

2 Likes

Thanks Eric! That opens up a whole new world for me!

This reminds me of this thread in GG
https://groups.google.com/g/tiddlywiki/c/0MqLimtsmxU/

You can do it how Eric said. Adding the fields with empty values "".

Or with vitual fields (link). But I think that you can use transclusion inside the filter: [[url]] :arrow_right: [enlist{Virtual fields}] where Virtual fields is the tiddler that contains in text the list of fields “FieldA FieldB”

To ordering the fields you have to do how Eric said in the end of the thread.

I would like to add to Eric’s sage advice it is possibly better not to alter the standard new tiddler buttons and process but to copy and edit it for custom tiddlers.

For example most tiddlywikis will have different tiddler types (not the type field), examples may be a todo, a contact, a project etc… and we like to make new ones of each time based on a template (or another tiddler).

What I have done in the past
Create a new tiddler with the $:/tags/SideBar containing a create new tiddler button/macro for each of the “standard tiddlers” I want in the current wiki. If you use a template or just have the tags and fields fields in the create tiddler action(s) it does not matter.

Your futures
Once you build this consider exporting the tiddlers that make up this new custom tiddler tools as a json file and import it to any wiki where you want these tiddlers types available.

If you decide to publish this for other users you can then hide the normal new tiddler buttons so only these custom new tiddler buttons are available.

My futures
I think this could be simplified and tools published to make new custom tiddlers buttons and templates for all users. After all most TiddlyWiki user or designers will need to do this eventually.