List Widget Filters "Only" operator

146 views
Skip to first unread message

John McDonnell

unread,
Jul 25, 2021, 4:16:12 PM7/25/21
to TiddlyWiki
Hi all, I'm looking for a way to filter tiddlers in a list that only contain certain tags.

For example, lets say I want to select only tiddlers with Tag1 and Tag2 an no other tags.
Tiddler A Tags: Tag1, Tag2, Tag3
Tiddler B Tags: Tag1, Tag2
Tiddler C Tags: Tag1, Tag2, Tag4

In this limited example I know the filter could be

<<list-links "[tag[Tag1]tag[Tag2]!tag[Tag3]!tag[Tag4]]">>

but if new tags are added I would need to return to manually exclude them with this filter.

Thanks in advance.

TW Tones

unread,
Jul 25, 2021, 7:10:26 PM7/25/21
to TiddlyWiki
Hi johnangus...

First you could place  [tag[Tag1]tag[Tag2]!tag[Tag3]!tag[Tag4]] in a tiddler or a macro

eg; $:/config/tag-filter
then reference is as {{$:/config/tag-filter}} as the whole filter or "... {$:/config/tag-filter} ..." within a filter.

Alternatively in a tiddler tagged $:/tags/Macro
\define  tag-filter()  [tag[Tag1]tag[Tag2]!tag[Tag3]!tag[Tag4]]
then reference is as <<tag-filter>> as the whole filter or "... <tag-filter> ..." within a filter.

However to make use of these as parameters to the list-links macro make use of the expanded macrocall widget

<$macrocall $name=list-links filter=<<tag-filter>>/>
or
<$macrocall $name=list-links filter= {$:/config/tag-filter}}  />

Regards
Tones

PMario

unread,
Jul 26, 2021, 1:39:12 AM7/26/21
to TiddlyWiki
Hi,

In TW you sometimes need to think different, because filter sets can dynamically change as you found out.

<$set name="condition" value="[tags[]count[]match[1]]">
<$list filter="[tag[a]filter<condition>]"/>
</$set>

In this example, the first filter tag[a] gets all tiddlers that have a tag a.
The second condition is
  - get all tags of that tiddler, 
  - count them and
  - compare to 1" ... So "a" is the only tag because of the initial filter -> \o/

The filter operator applies the condition to the current tiddler and returns its title, if the condition is not empty.


have fun!
mario

PMario

unread,
Jul 26, 2021, 1:44:43 AM7/26/21
to TiddlyWiki
UUPS,
I didn't read your OP good enough, because my solution works for 1 tag only. ... BUT it should contain enough info to figure out, how the filter should look like for your problem;)
-m

John McDonnell

unread,
Jul 26, 2021, 9:14:59 AM7/26/21
to TiddlyWiki
Thanks everyone, useful information.
@PMario - I'll take a look at that and:
1) Try and apply the example as written for a single tag to see if I can get it working
2) Try and extend to two tags

It looks like it should be straightforward enough and I'll be able to add a new tool to my belt.

Thanks
John

PMario

unread,
Jul 26, 2021, 4:15:35 PM7/26/21
to TiddlyWiki
Hi John,
If you found a solution, it would be nice if you share it.
If it still causes headaches, let us know.
-m

TW Tones

unread,
Jul 27, 2021, 8:26:23 AM7/27/21
to TiddlyWiki
A thought! untested.

If you could count the tags and they do not equal two then it can not have two tags.
Then say [tag[Tag1]] +[tag[Tag2]]

[all[current]tags[]count[]match[2]then<currentTiddler>] +[tag[Tag1]] +[tag[Tag2]]
Above untested

The store the above in a tiddler as I suggested in my first reply, then if you added another tag to the set update it only.

Tones

PMario

unread,
Jul 27, 2021, 5:27:24 PM7/27/21
to TiddlyWiki
On Tuesday, July 27, 2021 at 2:26:23 PM UTC+2 TW Tones wrote:

[all[current]tags[]count[]match[2]then<currentTiddler>] +[tag[Tag1]] +[tag[Tag2]]

Tony, Your filter uses all tiddlers that have 2 tags and starts to test them.

I did think about this:

<$set name="condition" value="[tag[Tag2]tags[]count[]match[2]]">
  <$list filter="[tag[Tag1]filter<condition>]">
    <<currentTiddler>> <br/>
  </$list>
</$set> 

My filter uses all tiddlers, that have at least Tag1 and tests them if it has Tag2 and only 2 tags. ... Those tiddlers could have 1,2 or more tags. ...

Performace will depend on how the tags are used and how many tiddlers have 2 tags ...

-mario

TW Tones

unread,
Jul 30, 2021, 1:32:10 AM7/30/21
to TiddlyWiki
Mario,

Yes, especially with larger tiddlywiki (or even if you think it my be one day), it is best to reduce the set as quickly as possible to a smaller list.

Tones
Reply all
Reply to author
Forward
0 new messages