mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-19 10:49:43 +00:00
46 lines
2.9 KiB
Plaintext
46 lines
2.9 KiB
Plaintext
created: 20211130114857532
|
|
filter1: [prefix[ca]then[ca]]
|
|
filter2: [suffix[at]then[at]]
|
|
filter3: other
|
|
modified: 20211204010918504
|
|
tags: [[Filter Run Prefix Examples]] [[Filter Syntax]] [[Cascade Filter Run Prefix]]
|
|
title: Cascade Filter Run Prefix (Examples)
|
|
type: text/vnd.tiddlywiki
|
|
|
|
The <<.op ":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 <<.op :cascade>> filter run returns a list of filters from the text fields of tiddlers tagged <<tag $:/tags/TiddlerColourFilter>> as shown below:
|
|
|
|
<ul>
|
|
<$list filter="[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]]">
|
|
<li><pre><$text text=<<currentTiddler>>/></pre></li>
|
|
</$list>
|
|
</ul>
|
|
|
|
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.
|
|
|
|
<<.operator-example 1 """[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 <<.op :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|TextReference]] and instances of the [[append operator|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:
|
|
|
|
<ul>
|
|
<$list filter="[{!!filter1}append{!!filter2}append{!!filter3}]">
|
|
<li><pre><$text text=<<currentTiddler>>/></pre></li>
|
|
</$list>
|
|
</ul>
|
|
|
|
For this example, `cat can bat bug` will be used as the input titles. Each input title will be evaluated by <<.op :cascade>> against each of the above filters in turn. To help understand what <<.op :cascade>> sees internally, the following table uses the [[Map Filter Run Prefix]] to show the result of each individual filter.
|
|
|
|
|^<<.operator-example c1.1 "cat can bat bug :map[prefix[ca]then[ca]]">>|^<<.operator-example c1.2 "cat can bat bug :map[suffix[at]then[at]]">>|^<<.operator-example c1.3 "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 <<.op :cascade>> is used. Click "Try it" below to see the final result:
|
|
|
|
<<.operator-example c1.4 "cat can bat bug :cascade[{!!filter1}append{!!filter2}append{!!filter3}]">> |