This page is part of a static HTML representation of the TiddlyWiki at https://tiddlywiki.com/

Then Filter Run Prefix (Examples)

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.

Tip
Note that each filter run of the subfilter receives the input of the subfilter operator as input

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 (2015-02-03)
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.