TiddlyWiki5/editions/tw5.com/tiddlers/filters/examples/get.tid

23 lines
1.7 KiB
Plaintext

created: 20150118134611000
modified: 20230310154010278
myfield:
tags: [[get Operator]] [[Operator Examples]]
title: get Operator (Examples)
type: text/vnd.tiddlywiki
<<.operator-example 1 "[all[current]get[draft.of]]" "the title of the tiddler of which the current tiddler is a draft">>
<<.operator-example 2 "[get[tags]]" "returns the tags of all tiddlers without de-duplication">>
<<.operator-example 3 "[get[tags]unique[]]" "returns the tags of all tiddlers with de-duplication">>
<<.tip """If a data tiddler contains a field with an empty value, the empty string is not appended to the results.""">>
<<.operator-example 4 "[all[current]get[myfield]]" "the empty value of field <<.field myfield>> is not returned by the <<.olink get>> operator">>
<<.operator-example 5 "[all[current]] :filter[has:field[myfield]] :map[get[myfield]]" "also returns the empty string">>
The above example works by first using the [[Filter Filter Run Prefix]] to only select titles that have the field <<.field myfield>> and then using the [[Map Filter Run Prefix]] to replace those titles with their value of that field. The [[Map Filter Run Prefix]] outputs an empty string when its filter run returns an empty [[selection|Title Selection]].
<<.operator-example 6 "[all[tiddlers]] :filter[get[created]compare:date:lt{HelloThere!!created}]" "return all tiddlers that are older than [[HelloThere]]">>
The above example demonstrates two different ways of accessing field values in filters: Use <<.olink get>> when the title is not known in advance as with the [[Filter Filter Run Prefix]] where <<.var currentTiddler>> is set to the current input title. Use a [[TextReference]] as an indirect [[Filter Parameter]] when the title is known.