Filter based on value of fields

I have a tiddler that has fields named in a pattern.

TrueOrFalse01=True, TrueOrFalse02=False, TrueOrFalse03=True, TrueOrFalse04=False

I would like to check if ALL of these fields have their value set to a pre-defined value.

My approach was to try and use a filter.
I am able to filter the fields for the given pattern, but not sure how to filter further based on the value of this result.

Expected first level output/result of filter

TrueOrFalse01=True, TrueOrFalse03=True

Here are various approaches I have tried to come up with, none of them get me desired output though:

{{{  [<currentTiddler>fields[]search:title:literal[True]] }}}
{{{ [<currentTiddler>fields[]regexp[TrueOfFalseField.*\d\d]contains[True]] }}}

The contains and search filter operators seem to search the field names and not the field values.
Or is my approach wrong?

This returns a value if any field has False, otherwise it returns no value. Good enough?

{{{ 
[<currentTiddler>fields[]prefix[TrueOrFalse]]
:map[<..currentTiddler>get<currentTiddler>match[False]]
+[unique[]]
}}}
1 Like

It works.

But I do not get this part:

[<..currentTiddler>get<currentTiddler>match[False]]

I tried combing the documentation but could not understand much of how this part works.

I tried isolating this part of filter to better understand but it generates no output. Why would these not work ?

{{{ [<currentTiddler>get<currentTiddler>match[False]] }}}

{{{ [<currentTiddler>get<currentTiddler>match[True]] }}}

{{{ [<currentTiddler>get<currentTiddler>] }}}

{{{ 
[<currentTiddler>fields[]prefix[TrueOrFalse]]
:map[<..currentTiddler>get<currentTiddler>match[False]]
+[unique[]]
}}}

OK, let’s refer to the above as having three filter runs.
In the first run, currentTiddler refers to the surrounding tiddler (probably the tiddler holding your code).
In the second run, currentTiddler refers to the input titles into that run, i.e the output from the first run.
In contrast, ..currentTiddler in the second run refers to the currentTiddler outside of that second filter run, i.e again your tiddler outside of it all.

See the :map filter prefix docs

(The reason behind the .. syntax is probably that in some operating systems you do things like cd.. to back upwards in a folder tree (“change directory upwards”). Something along those lines at least.)

1 Like

Sometimes TW development feels like Code Golf

1 Like

This is a bit topic adjacent, but is there a way to list all the values of a field?

Like, if I have tiddlers that all have the “Content-Type” of “Character” could I make the tabs macro list all the values, including character, for all tiddlers that have the Content-Type field?

Something like <<tabs '[has[Content-Type]get[Values]]'>> and each tab would be Character, Person, Note, etc. and inside each tab would list all tiddlers with that Content-Type in a bulleted list?

So tiddlers have fields titled Content-Type with the value, for example, Character or some other value?

Sure.

Pretty close: <<tabs '[has[Content-Type]get[Content-Type]]'>> i.e this filters out all tiddlers that have that field and then extracts the values from that field, which becomes the names on the tabs.

You will probably also want to specify some state tiddler and possibly a default tab, see the tabs macro in the docs.

1 Like

Hm, well that does work, but not what I had intended, I’ll make a separate discussion and go further into details as to not derail the main topic here!

Edit: Made the new topic, called Listing all tiddlers with the same field value, using the tabs macro?

I added something relevant to this Topic in the new one