Create new tiddlers based on templates

491 views
Skip to first unread message

bimlas

unread,
May 27, 2020, 9:55:31 AM5/27/20
to TiddlyWiki
Dear all,

There was probably a similar solution already, but I just figured it out: I found a simple way to create templates for different tiddler types. For example, in the "Software" tiddlers, display the "website" and "platform" fields, and in the "Song" tiddlers, display "author", "album" and "year" by default so you don't have to remember to enter the "required" fields.

To do this, create the mentioned tiddlers as "New tiddler template: Software" and "New tiddler template: Song" and add the desired fields to them. You can even enter a predefined text if you want to store the data not in fields but in the text of the tiddler itself.

Create a tiddler of any name, add the "$:/tags/SideBarSegment" tag and optionally the "list-before: $:/core/ui/SideBarSegments/tabs" field. The content should be:

<$vars titlePrefix="New tiddler template: ">
  <$list filter="[search:title
<titlePrefix>]">
    <$button message="tm-new-tiddler" param=<
<currentTiddler>> class=<<tv-config-toolbar-class>>>
      {{$:/core/images/new-button}} <$text text={{{ [all[current]removeprefix
<titlePrefix>] }}}/>
    </$button>
<br/>
  </$list>
</$vars>

TonyM

unread,
May 27, 2020, 9:53:47 PM5/27/20
to TiddlyWiki
Bimlas,

I believe this was made possible by a minor change that ensured this would work like the clone.

I am revisiting my own new tiddler from template process. I will share Shortly.

Regards
Tony

Sylvain Naudin

unread,
May 28, 2020, 2:45:14 AM5/28/20
to TiddlyWiki
Hi Bimlas,

Thanks for sharing, this quite smart and powerful !

Cheers,

PMario

unread,
May 28, 2020, 5:33:53 AM5/28/20
to TiddlyWiki
Hi,

In TW V5.1.22 the ActionCreateTiddler widget got some new functions, that make cloning and creating new tiddlers using templates much more versatile: https://tiddlywiki.com/#ActionCreateTiddlerWidget

-m
Message has been deleted

Paco Rivière

unread,
May 28, 2020, 3:00:59 PM5/28/20
to TiddlyWiki
Wonderful tip!

Just two points, that were no evident to me:

1. If you use a language plugin, you must change "New tiddler" in the first line of your code with the corresponding in you language, or the default new tiddler text will be in English.

2. Also if you want to have several templates you need to use different titlePrefix for each, or buttons will duplicate, and add a text after {{$:/core/images/new-button}} to distinguish the button for each template

El dimecres, 27 maig de 2020 15:55:31 UTC+2, bimlas va escriure:

bimlas

unread,
May 29, 2020, 5:14:38 PM5/29/20
to TiddlyWiki
PMario, 

In TW V5.1.22 the ActionCreateTiddler widget got some new functions, that make cloning and creating new tiddlers using templates much more versatile: https://tiddlywiki.com/#ActionCreateTiddlerWidget

I don't like using ActionCreateTiddler because it definitely creates a new tiddler, even if I press the cancel button in edit mode. However, I further developed the script (?), now it's using the default tiddler title.

\define create-tiddler-from-template()
 
<$action-sendmessage $message="tm-new-tiddler" $param=<<currentTiddler>> title={{$:/language/DefaultNewTiddlerTitle}}/>
\end

<div class="tc-sidebar-lists">
 
<$vars titlePrefix="$:/bimlas/new-tiddler-templates/">
   
<$list filter="[search:title<titlePrefix>!has[draft.of]]">
     
<$button class=<<tv-config-toolbar-class>> actions=<<create-tiddler-from-template>>>

       
{{$:/core/images/new-button}} <$text text={{{ [all[current]removeprefix<titlePrefix>] }}}/>
     
</$button> <br/>
   
</$list>
  </
$vars>
</div>

 

bimlas

unread,
May 29, 2020, 5:22:29 PM5/29/20
to TiddlyWiki
Paco,
 
1. If you use a language plugin, you must change "New tiddler" in the first line of your code with the corresponding in you language, or the default new tiddler text will be in English.

The "New tiddler" can be replaced by anything, such as "$:/you/templates/" (so they won't be included in search results), it's just to identify template tiddlers, this is not the name of the created tiddler, only the template.
 
2. Also if you want to have several templates you need to use different titlePrefix for each, or buttons will duplicate, and add a text after {{$:/core/images/new-button}} to distinguish the button for each template

 You may have misunderstood the use: the template buttons in the sidebar are for creating new tiddlers based on predefined templates. You name the created tiddler as you want, so if e.g. if I have a "New tiddler: Software" template and based on that I create a new tiddler, then I don't want to name it "New tiddler: Software 1", but for example "TiddlyWiki", "Firefox", "Linux" , etc.

The new version may make the operation clearer: https://groups.google.com/d/msg/tiddlywiki/VgifrVIzcKk/CDXTHxXNAQAJ
Reply all
Reply to author
Forward
0 new messages