Question about the currentTiddler variable

What if I have an entry for test which has a mytest field with a value of [tag<currentTiddler>], what about processing the value of this field as [tag[test]], is this possible to do?

The subfilter operator interprets its parameter as a filter. That parameter can be either a variable (as shown in the first example on that docs page) or a transcluded field value. So on the test tiddler — or in any scenario where <<currentTiddler>> = test — you could do the following:

{{{ [subfilter{!!mytest}] }}}

<$list filter="[subfilter{!!mytest}]" />

Demo:

Sidenote — I’m using edit mode to show the code and the preview side by side. However, when the tiddler “test” is in edit mode, <<currentTiddler>> = Draft of 'test', not test, as you can see in the first line of the preview. This means [subfilter{!!mytest}] will be parsed as [tag[Draft of 'test']], not [tag[test]], and the preview window won’t display the expected results (though they’ll be visible if you save the tiddler and return to view mode).

To force the preview to display the same results you’d see in the “live” tiddler, I wrapped the rest of the demo code in a $tiddler widget, <$tiddler tiddler={{!!draft.of}}>. Since {{!!draft.of}} holds the title of the tiddler being edited, this redefines <<currentTiddler>> to test, and we get the same results we would when viewing the test tiddler.

Edit: See my next post for the code used in the screenshot, plus an additional note.

1 Like

Thanks for the answer, I just researched this as well. But how do you filter like this for all entries? It’s a lot easier to filter than And also Because {!!mytest} is written as a text reference, it’s hard to transfer in other parameters.

Check out this post below if you are interested.

@etardiff – Nice explanation.

It would be nice (for the lazy folks like me) to also have your test code as text, so we can copy / paste the tests, instead of “typoing” it ourselves from an image :wink:

1 Like

Good catch! I did include the code for the subfilter test itself, but I hadn’t bothered with the rest of the code shown in the screenshot as most of it was added purely for display purposes. However, if anyone would like to play with it, here’s the test tiddler I made: test.tid (421 Bytes)

You’ll need to tag some tiddlers with test to get the sort of results shown above.

`<<currentTiddler>>`: <<currentTiddler>>

<$tiddler tiddler={{{ [{!!draft.of}!match[]] ~[<currentTiddler>] }}}>

`<<currentTiddler>>`: <<currentTiddler>>

`{{{ [subfilter{!!mytest}] }}}`

{{{ [subfilter{!!mytest}] }}}

`<$list filter="[subfilter{!!mytest}]" />`

<$list filter="[subfilter{!!mytest}]" />

</$tiddler>

Eagle-eyed readers may also notice that I’ve changed the $tiddler widget slightly from the code used in my previous post…

  • Original: <$tiddler tiddler={{!!draft.of}}>
  • Revised: <$tiddler tiddler={{{ [{!!draft.of}!match[]] ~[<currentTiddler>] }}}>

… because, contrary to my expectations, <$tiddler tiddler={{!!draft.of}}> produces the “correct” results in the preview, but not in the view-mode tiddler.

I’d assumed that since a tiddler in view mode lacks the draft.of field, <$tiddler tiddler={{!!draft.of}}> would be undefined, and <<currentTiddler>> would fall back to its original value — as in the following (working) example, where <<currentTiddler>> remains unchanged when <<currentTab>> is undefined:

<$tiddler tiddler=<<currentTab>>>

<<currentTiddler>>

</$tiddler>

image

But <$tiddler tiddler={{!!draft.of}}> doesn’t seem to work the same way… perhaps because tiddler={{!!draft.of}} is being treated as tiddler="" rather than a null value. So I added the fallback {{{ [{!!draft.of}!match[]] ~[<currentTiddler>] }}} to cover instances in which {{!!draft.of}} is equal to “”.

For some time, I’ve been vaguely annoyed by the lack of any compact and easy-to-type way of writing something to get this effect:

Given that we have other variants (like ..currentTiddler and storyTiddler and thisTiddler) … shouldn’t there also be a variant of currentTiddler that helps us bypass the inscrutable preview problem?

I’d never really considered it before, but that’s a good point. I’m not sure whether there’s enough general interest to get it into the core, but you could get around it with a custom function in a tiddler with the $:/tags/Global tag:

\function draftTiddler() [{!!draft.of}!match[]] ~[{!!title}]

Which would then enable a shorter workaround like

<$tiddler tiddler=<<draftTiddler>>>

<<currentTiddler>>

</$tiddler>

Generally I try to use at least one . in any custom function name; I find it makes it easier to identify functions vs. “simple” variables, and also enables me to use the function as a custom operator if needed. But I can’t imagine any scenario in which I’d want, say, [draft.of[HelloThere]], and I do like that <<draftTiddler>> parallels the other ...Tiddler variables. :thinking:

1 Like

I like that aspect, too… Still I think I’d want something that doesn’t emphasize “draft” though — because it’s really a version of currentTiddler (functionally), that also happens to work even in draft-preview window. Perhaps something like current.Tiddler would both capture that meaning and conform to the “include a period” convention…?

(Of course if this is an ad-hoc solution in my wiki or yours the name doesn’t matter. Still, it’s satisfying to think through naming practices in a forum like this so that convergence on best practices benefits from lots of input.)