[TW5] Conditional content based on filter results

182 views
Skip to first unread message

Tobias Beer

unread,
May 8, 2016, 5:01:07 AM5/8/16
to TiddlyWiki
Hi everyone,

Hope I didn't get too rusty since March.

I am struggling to formulate a filter logic for batch operations
that allows to specify a filter whereas when the filter yields...
  • results => shows a button to delete all those tiddlers
  • no results => does not show a button since there are not tiddlers to be deleted
The filter is specified by the user in an input field.

Feels like a filter to model this conditional logic isn't quite there yet, is it?
 
<$list filter="[foo[bar]is[emptyList]]">
<$button>foo</$button>
</$list>

What I am not looking for is to just
although I am not sure that that would exist either (in a simple solution).

Best wishes,

Tobias.

Eric Shulman

unread,
May 8, 2016, 5:39:00 AM5/8/16
to TiddlyWiki
To conditionalize output based the empty/non-empty state of the filter results, use the *emptyMessage* param in the $list widget.

To make things more readable, I tend to put the output rendering code into separate macros, thus:

\define showitem() <$button>{{!!title}}</$button>
\define showempty() no items
\define filter() [foo[bar]]
<$list filter=<<filter>> emptyMessage=<<showempty>>> <<showitem>> </$list>

enjoy,
-e

P.S. welcome back

Mat

unread,
May 8, 2016, 6:08:43 AM5/8/16
to TiddlyWiki

Tobias Beer

unread,
May 8, 2016, 3:25:45 PM5/8/16
to TiddlyWiki
Hi Eric,
 
To conditionalize output based the empty/non-empty state of the filter results, use the *emptyMessage* param in the $list widget.

Thanks for your feedback. There remains an issue though.
The user can input any filter that may or may not yield matches.
If there are any matches, I want to display a single button,
followed by a list of all matches.

I guess I will have to use a variable and a helper macro to append a

+[limit[1]]

to the filter string being tested so as to check (once) if there are any results.

Best wishes,

Tobias.

Mat

unread,
May 9, 2016, 2:05:16 PM5/9/16
to TiddlyWiki
@Tobias

+[limit[1]]

If you could put up a solution on tb5 it would be appreciated!

<:-)
Reply all
Reply to author
Forward
0 new messages