Variables in title when clicking "New Tiddler" button?

93 views
Skip to first unread message

Logan Chin

unread,
Sep 6, 2020, 12:02:15 PM9/6/20
to TiddlyWiki
Hi all,

I've spent the past couple days trying to optimize my wiki for when school starts.

I have created a "New Tiddler" button to press for each new lecture of a given class; I have designed it such that the requisite course tags/fields are filled every time a new tidier is created.

 I am wondering if there is some way to automate the date in the title of the tiddler? Or would it be possible to have a title such as "Lecture#(x)" in which every click increases x by 1? I have provided the code below:

<$button>
<$action-sendmessage $message="tm-new-tiddler"
   title=""
   tags= "[[IntrotoPolySci]]"
   year=<<now "YYYY">>
   month=<<now "MMM">>
   day=<<now "DD">>
/>
New Lecture
</$button>

Thanks!

Eric Shulman

unread,
Sep 6, 2020, 4:15:14 PM9/6/20
to tiddl...@googlegroups.com
On Sunday, September 6, 2020 at 9:02:15 AM UTC-7, Logan Chin wrote:
I have created a "New Tiddler" button to press for each new lecture of a given class; I have designed it such that the requisite course tags/fields are filled every time a new tidier is created.
I am wondering if there is some way to automate the date in the title of the tiddler? Or would it be possible to have a title such as "Lecture#(x)" in which every click increases x by 1?

Try this:

1) Create a tiddler called "NewLectureButton", containing:
\define addLecture()
<$vars num={{{ [prefix<currentTiddler>sort[modified]last[]split[Lecture #]rest[]else[0]add[1]] }}}>
<$vars newTitle={{{ [<currentTiddler>addsuffix[ Lecture #]addsuffix<num>] }}}>
<$set name="newTags" filter="[<currentTiddler>]">
<$action-sendmessage $message="tm-new-tiddler" title=<<newTitle>> tags=<<newTags>>
   year=<<now "YYYY">> month=<<now "MMM">> day=<<now "DD">>
/>
\end
<$button actions=<<addLecture>>>New Lecture</$button>

Then, to use it:
1) Create a tiddler with a given course title (e.g., "Basket Weaving 101")
2) Enter whatever text you like (e.g., a course description, professor's name, room #, etc.)
3) Include the following somewhere in the content:
{{||NewLectureButton}}

How it works:
* The NewLectureButton tiddler displays a button that triggers an "action macro" (addLecture) when pressed.  This macro performs the following steps:
* "$vars num=..." calculates the next lecture number:
** Find all tiddlers that start with the course name (prefix<currentTiddler>)
** Get the most recent one (sort[modified]last[])
** Remove everything except the last lecture number (split[Lecture #]rest[])
** If this is the first lecture, use default number (else[0])
** Add 1 to the last lecture number (add[1])
* "$vars newTitle=..." constructs the new title by adding " Lecture #n" to the end of the course name (i.e., the current tiddler title)
* "$set name=newTags..." constructs a new tag from the course name, allowing for spaces in the course name
* The action-sendmessage creates a new tiddler, opened for editing, using the calculated title, tags, year, month, and day

Let me know how it goes...

enjoy,
-e

TW Tones

unread,
Sep 7, 2020, 4:21:59 AM9/7/20
to TiddlyWiki
Logan

If you use actioncreate tIddler you can set a base title. If the tiddller already exists it increments a number in the title.

You can even retrive the title that was created.

Regards
Tony

Logan Chin

unread,
Sep 8, 2020, 4:16:48 PM9/8/20
to TiddlyWiki
Thank you both! will try your suggested solutions out.
Reply all
Reply to author
Forward
0 new messages