mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-08-28 20:12:41 +00:00
50 lines
2.3 KiB
Plaintext
50 lines
2.3 KiB
Plaintext
caption: filter
|
|
created: 20200929174420821
|
|
modified: 20210522162551921
|
|
op-input: a [[selection of titles|Title Selection]] passed as input to the filter
|
|
op-neg-input: a [[selection of titles|Title Selection]] passed as input to the filter
|
|
op-neg-output: those input titles that <<.em "do not">> pass the filter <<.place S>>
|
|
op-output: the [[selection of titles|Title Selection]] that pass the filter <<.place S>>
|
|
op-parameter: a [[filter expression|Filter Expression]]
|
|
op-parameter-name: S
|
|
op-purpose: apply a subfilter to each input title and return the titles that return a non-empty result from the subfilter
|
|
tags: [[Filter Operators]] [[Negatable Operators]]
|
|
title: filter Operator
|
|
type: text/vnd.tiddlywiki
|
|
|
|
<<.from-version "5.1.23">> The <<.op filter>> operator runs a subfilter for each input title, and returns those input titles for which the subfilter returns a non-empty result (in other words the result is not an empty list). The results of the subfilter are thrown away.
|
|
|
|
Simple filter operations can be concatenated together directly (eg `[tag[HelloThere]search[po]]`) but this doesn't work when the filtering operations require intermediate results to be computed. The <<.op filter>> operator can be used to filter on an intermediate result which is discarded. To take the same example but to also filter by those tiddlers whose text field is longer than 1000 characters:
|
|
|
|
```
|
|
<$vars myfilter="[get[text]length[]compare:integer:gteq[1000]]">
|
|
<$list filter="[tag[HelloThere]search[po]filter<myfilter>]">
|
|
<div>
|
|
<$link>
|
|
<$text text=<<currentTiddler>>/>
|
|
</$link>
|
|
</div>
|
|
</$list>
|
|
</$vars>
|
|
```
|
|
|
|
Note that within the subfilter, the "currentTiddler" variable is set to the title of the tiddler being processed. The value of currentTiddler outside the subfilter is available in the variable "..currentTiddler". <<.from-version "5.2.0">>
|
|
|
|
<<.tip "Compare with the similar [[subfilter|subfilter Operator]] operator which runs a subfilter and directly returns the results">>
|
|
|
|
<<.tip "Compare with the analogous named filter run prefix `:filter`">>
|
|
|
|
```
|
|
\define larger-than-1k() [get[text]length[]compare:integer:gteq[1000]]
|
|
|
|
{{{ [tag[HelloThere]filter<larger-than-1k>] }}}
|
|
```
|
|
|
|
is equivalent to:
|
|
|
|
```
|
|
{{{ [tag[HelloThere]] :filter[get[text]length[]compare:integer:gteq[1000]] }}}
|
|
```
|
|
|
|
<<.operator-examples "filter">>
|