The :then Filter Run Prefix (a PR Under Review)

Background

Following discussion by @saqimtiaz here and @Yaisog here

@Yaisog created a PR and developed the new :then filter run prefix. A demo is available for test. See

Use cases

This filter run prefix is very useful, as it is one of the missing filter prefix in TiddlyWiki filter language. In general you can use it like

<$list filter="[condition] :then[true-part] :else[false-part]">

For example see:

<$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>

You can contribute: I am sure you can give a try and add your own use cases/examples here.

6 Likes

Example: A Three-Way Conditional View Template

Write a wikitext script to transclude tiddlers through:

  • Template1 if a tiddler tagged with parent BUT NOT with second
  • Template2 if a tiddler tagged with parent and also with second
  • baseTemplate if a tiddler not tagged with parent NOR with second
<$list filter="
    [all[current]tag[parent]]
    :then[<currentTiddler>tag[second]then[Template2]else[Template1]]"
  emptyMessage={{baseTemplate}} variable=thisTemplate>
      <$transclude tiddler=<<thisTemplate>> mode=block />
</$list>

Example: Conditional Default Tiddlers If Wiki Served over a Certain URL

Write a filter for $:/DefaultTiddlers to show different set of default tiddlers with below conditions.

  • if served over https://tiddlywiki.com/ show all tiddlers tagged HelloThere
  • if not (like opened from local drive) show all tiddlers tagged Start

To implement this:

  • Open $:/ControlPanel
  • Open Info tab and then → Basics tab
  • In Default Tiddler input box enter the below filter
[{$:/info/url/full}match[https://tiddlywiki.com/]]
:then[tag[HelloThere]]
:else[tag[Start]]

@Yaisog
This is a simple example worth to be included into doc.

2 Likes