I can't remember how to use "and" and "or" in a filter

The question is stupid, I should know the answer, but I’m not getting it.
How can I, given two conditions, create filters that do “and” and “or”?

For example, these are the two conditions:

[<currentTiddler>get[Field1]count[]match[0]]
[<currentTiddler>get[Field2]count[]match[0]]

How can I combine them to get these two filters?

both fields are empty (1 and 2)
at least one field is empty (1 or 2)

One way to get and is to string together multiple filter operators inside the same filter run. One way to get or is the use two separate filter runs.

* ''both fields'' (and)
** <$text text={{{[<currentTiddler>!has[created]!has[modified]]}}}/>
** <$text text={{{[<currentTiddler>!has[doesnotexist1]!has[modified]]}}}/>
** <$text text={{{[<currentTiddler>!has[created]!has[doesnotexist]]}}}/>
** <$text text={{{[<currentTiddler>!has[doesnotexist1]!has[doesnotexist2]]}}}/>
* ''either field'' (or)
** <$text text={{{[<currentTiddler>!has[created]] [<currentTiddler>!has[modified]]}}}/>
** <$text text={{{[<currentTiddler>!has[doesnotexist1]] [<currentTiddler>!has[modified]]}}}/>
** <$text text={{{[<currentTiddler>!has[created]] [<currentTiddler>!has[doesnotexist]]}}}/>
** <$text text={{{[<currentTiddler>!has[doesnotexist1]] [<currentTiddler>!has[doesnotexist2]]}}}/>

Paste above at tiddlywiki.com or click this link to directly view it at the share site

Thank you!
…unfortunately, sorry :sweat_smile:, I can’t figure out how I should go about creating an “and” filter using the filters I indicated.
Doing it like so doesn’t work (probably beacuse the “get” operator wants a tiddler before it)

[<currentTiddler>get[Field1]count[]match[0]get[Field2]count[]match[0]]

So I tried it like this:

[<currentTiddler>get[Field1]count[]match[0]<currentTiddler>get[Field2]count[]match[0]]

But like this is not “if both fields count = 0” like I’d want, but only “if Field2 count=0”.
Any ideas on how to do it?

2 Likes

Try this:

[<currentTiddler>get[Field1]] [<currentTiddler>get[Field2]] +[count[]match[0]]
1 Like

I wasn’t clear in my response that I replaced your get[field]count[]match[0] with !has[field]

This will output the tiddler name if it has neither field:

[<currentTiddler>!has[Field1]!has[Field2]]

This will output the tiddler name if either of the two fields is missing:

[<currentTiddler>!has[Field1]] [<currentTiddler>!has[Field2]]
1 Like

Just out of curiosity, if I had to do the opposite, what should I do?
( instead of match[0]!match[0] )

I don’t understand why, but simply adding “!” to the “match” operator

[<currentTiddler>get[Field1]] [<currentTiddler>get[Field2]] +[count[]!match[0]]

doesn’t seem to work


But
I actually looked more closely at the documentation of the “has” operator and the best solution for both cases is to use that operator. I was wrongly convinced that an existing but empty field could create problems.

So really no problem.
(Thanks again to both of you! :grinning_face_with_smiling_eyes:)

In similar cases, rather than !match[0] I have instead used the compare:number:gt[0]] or compare:number:ne[0]]

1 Like