How to count items within a field of a tiddler that matches a certain pattern

133 views
Skip to first unread message

Christine

unread,
Feb 11, 2019, 1:33:04 AM2/11/19
to TiddlyWiki
Hi! I'm trying to create a counter for checklists that I use in my Tiddlywikis. I want it to count the number of checked items and the total number of items in the checklist. So it would say e.g. Completed 3/5.

It's not difficult to do this with the built-in task management system, but I really don't want each task to have its own tiddler - I wanted a checklist that allows me to easily add new items without creating or editing a tiddler each time. So I settled on the Simple Checklist plugin, which is great.

Any items you add to the checklist get stored in a state tiddler in the field ckl_items-enabled. Any checked checkboxes tag the state tiddler with the item name, and remove it when unchecked. I actually altered it so mine instead writes checked items to a field called ckl_checked.

Say I add a checklist to a tiddler named To Do. The state tiddler is created as To Do_state. I can create the counter I want like this:

<$count filter="[list[To Do_state!!ckl_checked]]" /> / <$count filter="[list[To Do_state!!ckl_items-enabled]]" />

However, I don't want to write in the tiddler name manually each time, so I'd like to create a macro that tells it to find the relevant field in a tiddler with a prefix of <currentTiddler> and a suffix of _state. But I can't figure out the correct syntax for this. I either get a wrong count, or it thinks I want a field of the current tiddler.

I'm still pretty new to trying to understand the inner workings of Tiddlywiki. I've rarely played around with it in this way, and usually can find examples to learn from, but I'm struggling here. Any help would be appreciated!

I'm also open to alternative ways of making the counter, if anyone has other ideas! 

Eric Shulman

unread,
Feb 11, 2019, 2:08:52 AM2/11/19
to TiddlyWiki
On Sunday, February 10, 2019 at 10:33:04 PM UTC-8, Christine wrote:
Say I add a checklist to a tiddler named To Do. The state tiddler is created as To Do_state. I can create the counter I want like this:
<$count filter="[list[To Do_state!!ckl_checked]]" /> / <$count filter="[list[To Do_state!!ckl_items-enabled]]" />
However, I don't want to write in the tiddler name manually each time, so I'd like to create a macro that tells it to find the relevant field in a tiddler with a prefix of <currentTiddler> and a suffix of _state. But I can't figure out the correct syntax for this. I either get a wrong count, or it thinks I want a field of the current tiddler.

This should do what you want:
<$count filter="[<currentTiddler>addsuffix[_state]list[!!ckl_checked]]" />
/
<$count filter="[
<currentTiddler>addsuffix[_state]list[!!ckl_items-enabled]]" />

* The first part of the filter constructs the target tiddler title by combining the current tiddler title with the "_state" suffix.
* The second part uses the list[...] filter syntax as before, but *omits the literal tiddler title*, so that the remaining field reference (e.g., [!!ckl_checked]) is relative to the target tiddler title preceding it in the filter.

Let me know how it goes.

enjoy,
-e
Eric Shulman
TiddlyTools.com: "Small Tools for Big Ideas!" (tm)
InsideTiddlyWiki: The Missing Manuals

Christine

unread,
Feb 11, 2019, 3:06:42 AM2/11/19
to TiddlyWiki
Unfortunately, it's not working - I get a count of 0. As a test, I added one of the fields to the current tiddler and found this code has the same problem I've been encountering - it counts the items in the field in the current tiddler, not the state tiddler.

Mohammad

unread,
Feb 11, 2019, 4:27:59 AM2/11/19
to TiddlyWiki
I think the problem is with <currentTiddler>

Check the below code at Tiddlywiki.com

1 Create some tiddlers tagged with xx
2 Put some items in their km filed
3 Put below code in a tiddler and see the results
4 It works 

<$list filter="[tag[xx]]">
<$text text=<
<currentTiddler>>/>: <$count filter="[list[!!km]]" /><br>
</$list>


--Mohammad

FrD

unread,
Feb 11, 2019, 6:08:09 AM2/11/19
to TiddlyWiki
Hi.

You could try :

\define ckl_state() $(currentTiddler)$_state

<$tiddler tiddler=<<ckl_state>>>
<$count filter="[list[!!ckl_checked]]" /> / <$count filter="[list[!!ckl_items-enabled]]" />
/$tiddler>

Regards

FrD

Christine

unread,
Feb 13, 2019, 3:41:18 AM2/13/19
to TiddlyWiki
Brilliant, FrD - works perfectly. Thanks so much.

And Mohammad, thank you for your idea as well. It also works, but I'd have to do a more complicated setup where each state tiddler is auto-tagged with an individual tag, so I'll go with FrD's solution. But much appreciated!

Using Simple Checklist, this counter and Dropboard now means I can use TW as a kanban board that meets my needs. Thanks all!
Reply all
Reply to author
Forward
0 new messages