[tw5] Filter double conditional problem

54 views
Skip to first unread message

Mark Green

unread,
Aug 5, 2020, 2:17:29 PM8/5/20
to TiddlyWiki
Here's what I want to write in a filter:

If the current tiddler
 - doesn't have the "reaction" tag
 - doesn't have an "a-actions" field
 - has a "m-components" list with one member
 - then display an extra icon.

I originally wrote this as

[all[current]!tag[Reaction]!has[a-actions]list[!!m-components]count[]compare:number:eq[1]]

But this does not work because list[] ignores its input, so even if it's been emptied out by the earlier filters, it still displays the icon if m-components has one member but the tiddler does have Reaction or a-actions.

I then tried using a set intersection:

[all[current]!tag[Reaction]!has[a-actions]]+[list[!!m-components]count[]compare:number:eq[1]]

But this has the same problem and I'm not sure why, as the first set should be empty. In fact looking at it if it's a set intersection, my reasoning would have been that it would never trigger because the second set can only be empty or contain "1", and so unless the tiddler was named "1" that would not be present in the first set and the intersection would be empty. But it seems intersections don't work that way?

How do intersections correctly work and how can I do this?

Mark S.

unread,
Aug 5, 2020, 3:16:25 PM8/5/20
to TiddlyWiki
It's a shame that the intersection operator doesn't follow the rule of sets.

The intersection of the empty set with another set should be the empty set.

So this should work:

<$list filter="[all[current]!tag[Reaction]!has[a-actions]has[m-components]]+[!isblank[]list[!!m-components]count[]compare:number:eq[1]]" emptyMessage="NO ICON">
ICON 1
</$list>

But it doesn't. It always wants to generate whatever happens after the + even though nothing that is generated following the +  matches the first set. 

So instead you have to break it out into two list widgets:

<$list filter="[all[current]!tag[Reaction]!has[a-actions]has[m-components]]" >
<$list filter="[list[!!m-components]count[]compare:number:eq[1]]"> 
ICON 2
</$list>
</$list>


HTH

Eric Shulman

unread,
Aug 5, 2020, 3:48:52 PM8/5/20
to tiddl...@googlegroups.com
On Wednesday, August 5, 2020 at 11:17:29 AM UTC-7, Mark Green wrote:
If the current tiddler 
 - doesn't have the "reaction" tag
 - doesn't have an "a-actions" field
 - has a "m-components" list with one member
 - then display an extra icon.

What if you test the list first, like this:
[<currentTiddler>list[!!m-components]count[]match[1]then<currentTiddler>!tag[Reaction]!has:field[a-actions]]

Note the use of "then<currentTiddler>" so that the results of "count[]match[1]" isn't the number "1"
but is instead, the name of the tiddler that satisfied the conditional.

Also note the use of !has:field[a-actions] instead of !has[a-actions].  The difference is that without the ":field" suffix,
the has[...] filter requires a non-empty field value.  Using has:field[...] checks to see if the field exists at all, even
if the field value is empty.

-e

Reply all
Reply to author
Forward
0 new messages