I recently came across this unexpected behavior of filter functions, which might be intended, but surprised me:
If I have a tiddler with the fields
- title: Idiosyncrasy
- caption: Idiosyncrasy Caption Field
Then this code
\define demo-subfilter() [<currentTiddler>]
\function .demo-function() [<currentTiddler>]
{{{ [<currentTiddler>get[caption]!is[blank]else<currentTiddler>] :map[subfilter<demo-subfilter>] }}}
{{{ [<currentTiddler>get[caption]!is[blank]else<currentTiddler>] :map[.demo-function[]] }}}
will produce this output
Idiosyncrasy Caption Field
Idiosyncrasy
Now I thought that the :map
filter run prefix will set currentTiddler
inside the run to the currently processed input title, which in this case should be the caption field of the tiddler. This then is the output of the subfilter. However, the filter function outputs the title, which is the value of the currentTiddler
variable outside the :map
run, not inside where the filter function is called.
Was I using the filter function in the wrong way?
I have set up a sharing edition TW with the code above:
Sharing Edition
Merry Christmas
Yaisog
PS: Shameless plug: I would never have figured this out in a live wiki without the debug-log Filter Operator.