A more elegant filter?

81 views
Skip to first unread message

TW Tones

unread,
Jul 14, 2021, 3:31:55 AM7/14/21
to TiddlyWiki
Folks,

I am not sure its it is a form of writer's block but I have this filter in a list on the view template which detects if the current tiddler has the either of the tags todo or project and displays the content "once" if it has one or both of the tags.

[all[current]tag[todo]] [all[current]tag[project]] +[limit[1]]

However it seems to me there should be a way to provide a list of tags and have a test that determines if the currentTiddler has anyone of these. In some ways the reverse of the above. This would make it easier to simply name another tag if needed without repeating the "[all[current]" part of the filter.

Yet, for some reason I can wrap my head around a suitable filter, thus I am posting here to see if anyone can present a more elegant filter possibly of the form;

todo project othertag something.

Thanks in advance
Tones


TW Tones

unread,
Jul 14, 2021, 4:09:51 AM7/14/21
to TiddlyWiki
Ok, the writers block has passed. Here I use the intersection filter run prefix available 5.1.23+
Perhaps you still have a more elegant solution?

Here I test and illustrate the filters using the transclude filter format, but they could be used in a list widget filter.

Provide a list of named tags and test those that intersect with the set of titles in the tags field. Limit the output to one, so if used in a list widget the content is displayed only once if either match
{{{ todo project :intersection[enlist{!!tags}] +[limit[1]] }}}

Here I obtain the set of tags from a a text reference but it could equally be a variable.
{{{ [enlist{smart-filter!!tag-list}] :intersection[enlist{!!tags}] +[limit[1]] }}}

Here rather than use the limit[1] I have done this so the count of matches is passed through, and to avoid 0 matches being passed through use !match[0]
{{{ [enlist{smart-filter!!tag-list}] :intersection[enlist{!!tags}] +[count[]!match[0]] }}}

Did you do this before the intersection prefix was available?
This example I believe illustrates the differences with the introduction of the intersection as documented here

Regards
Tones

TW Tones

unread,
Jul 14, 2021, 4:19:24 AM7/14/21
to TiddlyWiki
In the previous filter examples it is more readable to use [tags[]] which is equivalent to [enlist(!!tags}]
{{{ todo project :intersection[tags[]] +[limit[1]] }}}

Tones

PMario

unread,
Jul 14, 2021, 5:18:01 AM7/14/21
to TiddlyWiki
Try this

<$set name=pattern value="^project$|^todo$">
<$list filter="[all[current]search:tags:regexp<pattern>]">
found <<pattern>>
</$list>
</$set>

-m

TW Tones

unread,
Jul 14, 2021, 7:37:09 AM7/14/21
to TiddlyWiki
Ah Yes, The Regex approach. One day I must bit the bullet and learn regex

Will this method deal with tags containing spaces or if there are accidental partial matches eg mytodo vs todo etc... I would assume it does but that "fact" is invisible if you don't understand regex.

Can you get any more elegant than my suggestions?

Thanks Mario
Tones
Reply all
Reply to author
Forward
0 new messages