There are a lot of different filter operators available in TiddlyWiki – as of this writing, 172 of them. Many if not most of them are very specific and rarely needed. So there's no need to learn them all; instead, anytime you can't remember the details of or don't know of an appropriate operator, you should review the comprehensive documentation. You might want to bookmark that page right now.
That said, the list can be overwhelming at first, and you probably don't want to have to review it every time you want to write a simple filter, so let's learn some of the most common operators.
Links
backlinks[]
: Get all of the tiddlers that link to the input tiddler.- Example:
[[JaneDoe]backlinks[]]
gets all tiddlers that link to Jane.
- Example:
links[]
: Get all of the tiddlers that the input tiddler links to.- Example:
[tag[Meeting]links[]]
finds all tiddlers that were mentioned in any meeting.
- Example:
Tags
tag[X]
: Keep all of the input tiddlers that have the tagX
.- Example:
[tag[Application]]
finds all tiddlers taggedApplication
.
- Example:
tagging[]
: Get all tiddlers in the wiki that are tagged with the input tiddler.- Example:
[[Application]tagging[]]
is the same thing as[tag[Application]]
. - You need to use
tagging[]
instead oftag[]
when you don't know what tag(s) you want to look for ahead of time. For instance, let's say we wanted to find all tiddlers that are part of any project. In our wiki, we decided to tag our projectsProject
, then tag the tiddlers that are part of that project with the project tiddler (e.g., the parts of theOnboardingProject
are taggedOnboardingProject
). So we could use the filter[tag[Project]tagging[]]
– the first filter step returns all project tiddlers, and the second step finds all the tiddlers that any of those tiddlers is tagging.
- Example:
Fields
field:fieldname[value]
: Keep all of the input tiddlers that have a field calledfieldname
with a value ofvalue
.- Example:
[field:phone[888-555-1234]]
returnsJaneDoe
because that's Jane's phone number. - This usage is common enough that you can shorten it to
fieldname[value]
, provided that your field name doesn't conflict with another filter operator (for instance, if you had a field calledbacklinks
, you would have to usefield:backlinks
to refer to that field, since there is abacklinks
filter operator already).
- Example:
contains:fieldname[value]
: Likefield:
, but treats the field as a list containing multiple values, and only requiresvalue
to be one of the items in the list.- Example:
[contains:family[JohnDoe]]
returnsJaneDoe
andEmilyDoe
because both of them have John as a family member.
- Example:
has[fieldname]
: Keep all of the input tiddlers that have a non-empty field calledfieldname
.- Example:
[tag[Contact]!has[phone]]
finds any contact tiddlers we forgot to add phone numbers to. - For filtering purposes, TiddlyWiki treats empty fields and nonexistent fields the same.
- Example:
search:field1,field2[mysearch]
: Keep all of the input tiddlers whosefield1
orfield2
field matches the search querymysearch
.- Any number of fields can be listed in the suffix, separated by commas. The single suffix
*
searches all fields. If no suffix is provided, thetags
,title
, andtext
fields are searched. - Multiple words in the search query are searched separately with all words required to be somewhere in the text, and case is ignored, so that
my search
will find the phrase “Search my wiki”, but not “Search here”. You can change this behavior by adding an additional suffix; see the documentation for details.
- Any number of fields can be listed in the suffix, separated by commas. The single suffix
Miscellaneous
count[]
: Output a single value describing how many input tiddlers were passed to the operator.- Example:
[tag[Meeting]count[]]
returns3
if we have 3 tiddlers taggedMeeting
.
- Example:
sort[field]
: Sort the input tiddlers byfield
.- Example:
[tag[Meeting]sort[at]]
shows all meetings from earliest to latest. - The sort is not case-sensitive; uppercase and lowercase letters sort identically.
- Adding a
!
in front ofsort
reverses the order, showing all meetings from latest to earliest. - Leaving out the field, writing just
sort[]
, sorts by the title.
- Example:
get[field]
: Take all of the input tiddlers and output the values of the fieldfield
on those tiddlers.- Example:
[[JaneDoe]get[email]]
yields Jane's email address.
- Example:
Exercises
Compose and run filters to answer the following questions:
- How many tiddlers are in the wiki?
- How many of those are system tiddlers?
- What meetings contain a link to
JaneDoe
?- Hint: Work backwards.
- Which contact has the alphabetically earliest phone number?
- Which tiddlers have text in a field called
at
? - Which tiddlers contain the words
JaneDoe
andhelp
somewhere in their text field? Use only a single filter step.
In an exercise in the Searching section, we noted that a search for JohnDoe
did not find places where John was mentioned somewhere other than the text
field. Write and test a filter that finds mentions of John in any field.
What is the alphabetically last description that any button on the editor toolbar uses? (The description is what shows up when you hover over the button, minus the indication of the keyboard shortcut. No cheating by hovering over every button!)
You'll need some additional information for this one:
- Remember that everything's a tiddler? Buttons in TiddlyWiki's interface are tiddlers too!
- A tiddler is part of the editor toolbar if it is tagged
$:/tags/EditorToolbar
. - You'll need to start your filter with
all[shadows]
to get any results. - Your filter expression will have more steps than any we've seen so far. Add one step to the filter expression at a time, inspecting the result to determine how you need to modify the list (what step you need to add) next. You'll eventually reach a point where you have a bunch of results that are wrapped in curly braces, like
{{$:/language/Buttons/Paint/Description}}
. When you get here, add the following filter steps to the end of your filter:split[{{]split[}}]
.
And here are two hints if you need them:
- How do you think we would define the description of a button in the TiddlyWiki data model?
- The content of a language tiddler, like
$:/language/Buttons/Paint/Description
, is stored in itstext
field.
This one is intended to be a little bit above your level at the moment – we won't get to some of the concepts involved until chapter 6, Looking Under the Hood – so you might not be able to figure it out. But spend some time working on it before you look at the answer.
go to answer