1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-04 03:03:18 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/filters/Introduction to Filters.tid

147 lines
5.1 KiB
Plaintext
Raw Normal View History

2014-04-10 18:56:51 +00:00
created: 20140410101941871
2014-10-09 19:51:58 +00:00
modified: 20141009180223576
2014-09-19 16:18:25 +00:00
tags: Learning
2014-04-10 18:56:51 +00:00
title: Introduction to Filters
2014-01-14 21:07:20 +00:00
type: text/vnd.tiddlywiki
2015-01-05 20:59:08 +00:00
This is a step-by-step introduction to how [[Filters]] are used. [[Filter Syntax]] presents a more technical summary of this information.
2014-03-04 21:17:01 +00:00
2014-10-08 18:02:54 +00:00
! Using Filters
Filters are a special notation for expressing lists of tiddlers within WikiText.
2014-10-08 18:02:54 +00:00
Filters are used in the ListMacro, TabsMacro, ListWidget, CountWidget, and many other areas of TiddlyWiki.
For example, this is how the ListMacro would be used to display the first example below:
2014-10-08 18:02:54 +00:00
```
<<list-links "HelloThere Introduction [[Title with Spaces]]">>
```
The easiest way to experiment with tiddler filters is by typing them into the ''Filter'' tab of the [[advanced search panel|$:/AdvancedSearch]].
2014-03-04 21:17:01 +00:00
! Simple Filters
The simplest example of a filter is a list of tiddler titles (if necessary quoted with double square brackets):
```
HelloThere Introduction [[Title with Spaces]]
```
The titles must be separated by one or more spaces and/or linebreaks.
! Filter Operators
Filter operators are used to select tiddlers in particular ways. For example, this filter consists of a single step that selects all tiddlers tagged ''introduction'':
2014-03-04 21:17:01 +00:00
```
[tag[introduction]]
```
The word `tag` is the ''operator'' and `introduction` is the ''parameter'' (sometimes called the ''operand'').
2014-03-04 21:17:01 +00:00
2014-09-10 22:42:13 +00:00
See [[Filters]] for a complete list of the available operators.
2014-03-04 21:17:01 +00:00
!! Default Filter Operator
2012-05-20 17:47:11 +00:00
The operator defaults to `title` if omitted, so `[[HelloThere]]` is equivalent to `[title[HelloThere]]`. If there are no spaces in the title, then the double square brackets can also be omitted: `HelloThere`.
! Negating Filter Steps
2014-03-04 21:17:01 +00:00
A filter step can be negated by preceding the operator with an exclamation mark (`!`). This example selects all tiddlers that are not tagged ''introduction'':
2014-03-04 21:17:01 +00:00
```
[!tag[introduction]]
```
! Operator Suffixes
Some filter operators can take an optional suffix that provides further information. For example, the `field` operator takes a suffix indicating the field to be compared. The following filter returns all tiddlers that have ''JeremyRuston'' in the `modifier` field:
2014-03-04 21:17:01 +00:00
```
[field:modifier[JeremyRuston]]
```
! Field Operator Shortcut
If an operator is not recognised, then it is instead interpreted as the suffix of the `field` operator. Thus, these two filters both return all the tiddlers that contain the string ''create'' in their `caption` field:
2014-03-04 21:17:01 +00:00
```
[caption[create]]
[field:caption[create]]
```
2012-05-20 17:47:11 +00:00
! Indirect Parameters
2013-05-31 12:32:34 +00:00
If a filter step has curly brackets around its parameter, then it is taken to be a TextReference to the actual value. For example, this filter selects all tiddlers containing the string contained in the ''$:/temp/search'' tiddler:
2013-05-31 12:32:34 +00:00
2014-03-04 21:17:01 +00:00
```
[search{$:/temp/search}]
```
2013-05-31 12:32:34 +00:00
! Variable Parameters
If a filter step has angle brackets around its parameter, then it is taken to be the name of a variable containing the actual value. For example, this filter selects all tiddlers containing the title of the current tiddler:
```
[search<currentTiddler>]
```
(The built-in `currentTiddler` variable keeps track of which tiddler is the current one.)
! ORing Multiple Filter Steps
You can use multiple filter steps at once. If you write the steps separately, the overall result is the set of tiddlers that match //any// of the steps. Each step is processed separately, adding its tiddlers to the overall result.
This example selects all tiddlers that are either tagged ''introduction'' or ''demo'':
2012-12-28 22:57:35 +00:00
```
2014-03-04 21:17:01 +00:00
[tag[introduction]] [tag[demo]]
2012-12-28 22:57:35 +00:00
```
2012-05-20 17:47:11 +00:00
Here's an example that returns tiddlers tagged ''alpha'' or ''beta'' that are also tagged ''task'' but not tagged ''done'':
2014-10-09 19:51:58 +00:00
```
[tag[alpha]] [tag[beta]] +[tag[task]!tag[done]]
```
! ANDing Multiple Filter Steps
A sequence of steps can also be combined by bashing them together and merging the outer square brackets. This is called a "run". The result is the set of tiddlers that match //all// of the steps in the run.
2014-03-04 21:17:01 +00:00
For example, here we select tiddlers that are tagged ''introduction'' and also tagged ''demo'':
2014-03-04 21:17:01 +00:00
```
[tag[introduction]tag[demo]]
```
Here's another example that selects all tiddlers tagged ''introduction'' that are //not// tagged ''demo'':
2014-03-04 21:17:01 +00:00
```
[tag[introduction]!tag[demo]]
```
2012-05-20 17:47:11 +00:00
! Negating Runs
2012-05-20 17:47:11 +00:00
Ordinarily, each run //adds// to the accumulated results. Prefixing a run with `-` instead causes the list of tiddlers selected to be //removed// from the results. For example, this example returns all the tiddlers tagged ''introduction'', apart from `HelloThere` and `Title with Spaces`:
2014-03-04 21:17:01 +00:00
```
[tag[introduction]] -HelloThere -[[Title with Spaces]]
```
This example returns all tiddlers tagged ''introduction'' that are not also tagged ''demo'':
2014-03-04 21:17:01 +00:00
```
[tag[introduction]] -[tag[demo]]
```
! Working with Filter Results
Usually, each run takes the entire store of available tiddlers as its source. Prefixing a run with `+` causes the results so far accumulated to be used as the source instead.
2014-03-04 21:17:01 +00:00
For example, this filter selects tiddlers tagged ''introduction'' or ''demo'', and then sorts the resulting list by the `title` field:
2014-03-04 21:17:01 +00:00
```
[tag[introduction]] [tag[demo]] +[sort[title]]
```