17th June 2023 at 6:37pm
Conditional Execution
The :then
filter run prefix can be used to avoid the need for nested ListWidgets or Macro Definitions in WikiText.
<$edit-text field="search" placeholder="Search title"/>
<$let searchTerm={{!!search}}>
<$list filter="[<searchTerm>minlength[3]] :then[!is[system]search:title<searchTerm>]" template="$:/core/ui/ListItemTemplate"/>
</$let>
That renders as:
Conditional (Sub)Filters
The :then
filter run prefix can be combined with the :else
prefix to create conditional filters. In this example, the fields used in searchSubfilter
for searching depend on the value of $:/temp/searchFields and the sort order used by sortSubfilter
depends on the value of $:/temp/searchSort. Checkboxes are used to set the values of these tiddlers.
Since the then
and else
operators cannot call subfilters or perform additional filter steps, they cannot be used for such applications.
<$checkbox tiddler="$:/temp/searchSort"
field="text"
checked="chrono" unchecked="alpha" default="alpha">
Sort chronologically (newest first)
</$checkbox><br/>
<$checkbox tiddler="$:/temp/searchFields"
field="text"
checked="title" unchecked="default" default="title">
Search <<.field title>> only
</$checkbox><p/>
<$let searchSubfilter="[{$:/temp/searchFields}match[default]] :then[search[prefix]] :else[search:title[prefix]]"
sortSubfilter="[{$:/temp/searchSort}match[chrono]] :then[!nsort[modified]] :else[sort[title]]"
limit=10 >
<$list filter="[all[tiddlers]!is[system]subfilter<searchSubfilter>subfilter<sortSubfilter>first<limit>]">
<$link/> (<$text text={{{ [{!!modified}format:date[YYYY-0MM-0DD]] }}} />)<br/>
</$list>
<$list filter="[all[tiddlers]!is[system]subfilter<searchSubfilter>rest<limit>count[]]">
... and <<currentTiddler>> more.
</$list>
</$let>
That renders as:
addprefix Operator (Examples) (2015-01-18)
All Filter Run Prefix (2023-07-11)
And Filter Run Prefix (2023-07-11)
Cascade Filter Run Prefix (2023-07-10)
Cascade Filter Run Prefix (Examples) (2023-03-05)
Else Filter Run Prefix (2023-03-22)
Except Filter Run Prefix (2023-03-22)
Filter Filter Run Prefix (2023-07-10)
Filter Filter Run Prefix (Examples) (2023-03-05)
... and 22 more.