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

Cascade Filter Run Prefix (Examples)

5th March 2023 at 12:52pm

The :cascade filter run prefix is used by the TiddlyWiki core to choose the colour for each tiddler as used in the tag pill generated by the tag macro.

:cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]]

The filter expression inside the above :cascade filter run returns a list of filters from the text fields of tiddlers tagged as shown below:

  • [has[color]then{!!color}]
  • [tag[TableOfContents]then[#1e90ff]]
    [tag[Working with TiddlyWiki]then[darkorchid]]
    
  • [[$:/config/DefaultTiddlerColour]has[text]get[text]trim[]]

For each input title, each of these filters is now applied to in turn until the first filter that returns a non-empty list. The first result from this non-empty list replaces that input title and is used as the colour for that tiddler.

[all[shadows+tiddlers]] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]] +[!is[blank]limit[10]]

Extended example

This example illustrates step-by-step how the :cascade filter run works.

A filter expression whose output returns a list of filters is required. Typically such a filter expression will construct the list of filters by querying some field in a set of tiddlers (likely via tag). To keep this example self-contained, 3 filters are stored in the filter1, filter2 and filter3 fields of this tiddler. Text references and instances of the append operator are used to combine the fields into a list of filters.

The filter [{!!filter1}append{!!filter2}append{!!filter3}], generates this list of filters:

  • [prefix[ca]then[ca]]
  • [suffix[at]then[at]]
  • other

For this example, cat can bat bug will be used as the input titles. Each input title will be evaluated by :cascade against each of the above filters in turn. To help understand what :cascade sees internally, the following table uses the Map Filter Run Prefix to show the result of each individual filter.

cat can bat bug :map[prefix[ca]then[ca]]
cat can bat bug :map[suffix[at]then[at]]
cat can bat bug :map[[other]]

Click "Try it" on the above 3 examples. The first non-blank value from each row as read from left to right will be returned when :cascade is used. Click "Try it" below to see the final result:

cat can bat bug :cascade[{!!filter1}append{!!filter2}append{!!filter3}]