searching for an item in a list stored as a tiddler's field

34 views
Skip to first unread message

CarloGgi

unread,
Oct 16, 2021, 11:51:15 AMOct 16
to TiddlyWiki
Hallo again,
I have some tiddlers with a special field, call it 'my_tiddlers_list' that stores, not hard to guess, a list of other tiddlers. By 'list' I mean to say the result of an <$action-listops xxx subfilter> widget, which is indeed some 'collection' of items separated by whitespace. I don't know if that's a 'list' in the sense of a type of variable (does TW have any variable types after all? It seems it doesn't).
Anyway, how do I go to check if a given tiddler 'tiddler-X' is included in the list of tiddlers stored into field 'my_tiddlers_list' of a[ny] tiddler? When I transclude the reference to 'my_tiddlers_list' as in {{!!my_tiddlers_list}}what i get is a unique 'string'. How do I split it up into its single member items? And once split the string into tokens (its member items), ho do I perform the comparison check?

So far, I came up with this very beginner-level code (I'm sure there are more elegant, concise ways to write it, merging the two filters into a single one and getting rid of one of the <$list> cycles) that tries to exploit 'enlist' operator. I leave some parts as 'pseudocode' because I don't know how to write them:

<$set name='my_tiddler' value='tiddler-X'>

<$list  filter="[tag[mytag]has:field[my_tiddlers_list]]" >
       <$list filter="[enlist{!!my_tiddlers_list}canIDoTheComparisonHere?]">
                orShallICompareHere? AndIfSo,How?
       </$list>      
</$list>

</$set>

but have no clue if I'm going the right way and how to do the comparison check.

Writing inner filter as filter="[enlist{!!my_tiddlers_list}[tiddler-X]]" doesn't work, nor does it work writing it as filter="[[enlist{!!my_tiddlers_list}][tiddler-X]]". In both cases I get <<currentTiddler>> valued as tiddler-X, regardless if it is included in my_tiddlers_list's list or not. For God's sake: why? And how do I write the check?

Thanks for helping,
CG

CarloGgi

unread,
Oct 16, 2021, 12:01:53 PMOct 16
to TiddlyWiki
with reference to my previous post, no need to say neither this code works for the inner filter:
<$set name='my_tiddler' value='tiddler-X'>
...
       filter="[enlist{!!my_tiddlers_list}<my_tiddler>]">

nor this:

<$set name='my_tiddler' value='tiddler-X'>
...
       filter="[[enlist{!!my_tiddlers_list}]<my_tiddler>]">

they both always output the value of <<my_tiddler>>, whether it was included in my_tiddlers_list or not.

CarloGgi

unread,
Oct 16, 2021, 1:35:00 PMOct 16
to TiddlyWiki
it turns out that in any filter written as

 filter="[[whatever_selection_here]title[xyzxyz]]"

all the selection preceding the step with tiddler's title is dropped and only that title is retained and passed on to the next step -if there is any. (And this wheter any xyzxyz tiddler exists or not by the way).

so for example

 filter="[tag[bar]title[foo]]"

outputs foo, even if tiddler foo has no 'bar' tag at all, and even if tiddler foo doesn't exist. This explains the apparently strange behavior above, and it is also quite counter-intuitive (one would intuitively expect the filter to output all the tiddlers -zero or one actually- that match title 'foo' and are tagged 'bar') so this behavior would deserve to be  highlighted strongly in the documentation IMHO.

Mark S.

unread,
Oct 16, 2021, 2:57:45 PMOct 16
to TiddlyWiki
This should do what you literally asked for ...

<$set name="my_tiddler" value="tiddler-X">
<$list filter="[tag[mytag]contains:my_tiddlers_list<my_tiddler>]" >
Tiddler <<currentTiddler>> has <<my_tiddler>> in field my_tiddlers_list <br/>
</$list>
</$set>

Aside:

Some filter operators filter an existing title list. Others generate lists without input. Filter operator "list" and "title" are in the latter category.

Mark S.

unread,
Oct 16, 2021, 2:59:13 PMOct 16
to TiddlyWiki
On Saturday, October 16, 2021 at 11:57:45 AM UTC-7 Mark S. wrote:

Aside:

Some filter operators filter an existing title list. Others generate lists without input. Filter operator "list" and "title" are in the latter category.


Also, filter operator tag can function in either manner, depending on context. 

Stobot

unread,
Oct 16, 2021, 3:57:16 PMOct 16
to TiddlyWiki
CarloGgi, just to address your note about it being unintuitive and not documented, I agree that at first it seems very strange! However it *is* documented in a few places where I think it should be (https://tiddlywiki.com/#title%20Operator). Do you have a suggestion where else it should be noted? Maybe we can submit a change request if you have a good idea. To expand a bit, this (below) is what's shown (note the last line in particular about it being a "constructor") and the alternative syntax that would do what you expected (field operator) which is a "modifier":

titleoperator.PNG

If you follow the link to constructor you'll see them described and call out the title example again, as it's the most common. 

selectionconstructors.PNG
You may have noticed that on the "title Operator" tiddler, there's a tag saying it's a "Selection Constructor". If you click it, you'll get a drop-down of other operators that work that way. 
Reply all
Reply to author
Forward
0 new messages