diff --git a/editions/tw5.com/tiddlers/filters/examples/subfilter Operator (Examples).tid b/editions/tw5.com/tiddlers/filters/examples/subfilter Operator (Examples).tid index af63b42d2..eac8828a3 100644 --- a/editions/tw5.com/tiddlers/filters/examples/subfilter Operator (Examples).tid +++ b/editions/tw5.com/tiddlers/filters/examples/subfilter Operator (Examples).tid @@ -1,8 +1,30 @@ created: 20181031175129475 -modified: 20181031175129475 +modified: 20211030223407188 tags: [[subfilter Operator]] [[Operator Examples]] title: subfilter Operator (Examples) type: text/vnd.tiddlywiki -<<.operator-example 1 "[subfilter[one two three]addsuffix[!]]">> -<<.operator-example 2 "[subfilter{$:/StoryList!!list}]">> +\define recent-mods() [has[modified]!sort[modified]limit[5]] +\define display-variable(name) +''<$text text=<<__name__>>/>'': <$text text={{{ [<__name__>getvariable[]] }}}/> +\end + +Literal filter operands can be used, but such cases are better rewritten without using <<.op subfilter>>: +<<.operator-example 1 "[subfilter[one two three]addsuffix[!]]" "same as `one two three +[addsuffix[!]]`">> + +The <<.op subfilter>> operator can be used to dynamically define parts of a [[filter run|Filter Run]]. This is useful for sharing a common pieces of a filter across multiple filters. + +For example, this variable: + +* <> + +can be used in one filter like this: + +<<.operator-example 2 "[tag[Filter Operators]subfilteraddsuffix[!]]" "same as `[tag[Filter Operators]has[modified]!sort[modified]limit[5]addsuffix[!]]`">> + +and in another similar filter like this: +<<.operator-example 3 "[tag[ActionWidgets]subfilteraddprefix[!]]">> + +Variables are not the only way to define dynamic subfilters. [[Text references|TextReference]] can be used to load a subfilter from a tiddler field (see also [[Filter Parameter]]): +<<.operator-example 4 "[subfilter{$:/StoryList!!list}limit[5]]">> +<<.operator-example 5 "[subfilter{$:/StoryList!!list}subfilter]">> diff --git a/editions/tw5.com/tiddlers/filters/subfilter Operator.tid b/editions/tw5.com/tiddlers/filters/subfilter Operator.tid index a02c1f125..30a49a122 100644 --- a/editions/tw5.com/tiddlers/filters/subfilter Operator.tid +++ b/editions/tw5.com/tiddlers/filters/subfilter Operator.tid @@ -1,6 +1,6 @@ caption: subfilter created: 20181031175129475 -modified: 20181031175129475 +modified: 20211030223407188 op-input: a [[selection of titles|Title Selection]] passed as input to the subfilter op-neg-input: a [[selection of titles|Title Selection]] passed as input to the subfilter op-neg-output: those input titles that are <<.em not>> returned from the subfilter <<.place S>> @@ -12,7 +12,7 @@ tags: [[Filter Operators]] [[Field Operators]] [[Selection Constructors]] [[Nega title: subfilter Operator type: text/vnd.tiddlywiki -<<.from-version "5.1.18">> Note that the subfilter operator was introduced in version 5.1.18 and is not available in earlier versions. +<<.from-version "5.1.18">> Note that the <<.op subfilter>> operator was introduced in version 5.1.18 and is not available in earlier versions. <<.tip " Literal filter operands cannot contain square brackets but you can work around the issue by using a variable:">> @@ -24,4 +24,6 @@ type: text/vnd.tiddlywiki <<.tip "Compare with the similar [[filter|filter Operator]] operator which runs a subfilter against each title, returning those titles that return a non-empty list (and discards the results of the subfilter)">> +The <<.op subfilter>> operator will act as a [[constructor|Selection Constructors]] whenever the filter defined by its operand is a [[constructor|Selection Constructors]]. Otherwise, it will act as a [[modifier|Selection Constructors]]. + <<.operator-examples "subfilter">>