Proposed new feature: "thisTiddler" variable

There’s a new Pull Request on GitHub for a new feature in response to several requests over the years.

It adds a new variable “thisTiddler” that within transclusions is set to the title of the transcluded tiddler. It is unchanged by macro invocations.

That means that it has two key usages:

  • Within a transcluded template, “thisTiddler” points to the template itself, making it possible for the template to access data stored in other fields of the template
  • Within a macro, “thisTiddler” points to the template that invoked the macro. If the macro was invoked by another macro, the template that invoked that macro is returned, and so on

This change is not yet merged but you can try it out in the preview for the PR at:

https://tiddlywiki5-git-this-tiddler-reference-jermolene.vercel.app/

Thoughts and questions welcomed.

11 Likes

Seems useful to have a fixed variable pointing to the original tiddler, nice addition. I can see that being very useful for sidebar tabs :

thistiddler.json (815 Bytes)

I hope this will not repeat what I consider a mistake for currentTiddler variable. IMO this variable should really be called only current because it often does not refer to a tiddler at all but just the “item” being processed. For example:

<$list filter='tiddler +[split[]]'>
Not a tiddler: <<currentTiddler>>
</$list>

(plus there is the all operator which has the neat all[current] operand)

Hi @twMat thisTiddler will always point to an actual tiddler title.

3 Likes

@jeremyruston I have looked at your demo and it works as expected and similar to my code tiddler method.

I have long argued for something similar and found my own solution through the transclusion variable. I was inclined to call it the “code tiddler” because it was where my wikitext code was present.

Concider three tiddlers

transcluding

* Here {{||transcluded}} 
* There {{transcluded}} 
* [[transcluded]]

transcluded

\define pipe() |
<<transclusion>>

{{{ [<transclusion>split<pipe>nth[2]] }}}

[[deeper]] {{deeper}}

deeper
{{{ [<transclusion>split<pipe>nth[2]] }}}

The {{{ [<transclusion>split<pipe>nth[2]] }}} will return the tiddler in which it is encoded. What I called the code tiddler.

@twMat I understand where you are coming from and in many ways currentTiddler could be replaced with title, even string. But you can of course;

<$list filter='tiddler +[split[]]' variable=string>
String: <<string>>
</$list>
  • The default use of widgets and macros is on the tiddler title, so its not surprising we used currentTiddler as the default variable name.
    • It has the side effect that people tend to write macros and transclusions that operate on the currentTiddler which is a useful side effect.
    • Although I acknowledge new users may find thinking in “strings”, or non-tiddler titles, a little harder.
  • However In the “code Tiddler” or “thisTiddler” example it is explicitly a title of a tiddler, so unlike currentTiddler it perhaps deserves tiddler in its name.
  • However @twMat your guidance remains true for future developments and I imagine a little more documentation could help eg in https://tiddlywiki.com/#currentTiddler%20Variable

The default variable for a list and other widgets is often currentTiddler, so it is convenient to write macros that act on the currentTiddler. In other cases it may be more appropriate to use a different variable name, to better reflect the meaning of the variable or to ensure the currentTiddler variable remains untouched.

<$list filter="Mon Tue Wed Thur Fri Sat Sun" variable=day-of-week>
   <<day-of-week>> in "<<currentTiddler>>"<br>
</$list>

@jeremyruston since I have had the equivalent of thisTiddler for some time I can share some of the uses for this in addition to;

  • An example here is you can write single tiddler buttons that use content in its own fields, however if cloned continue to work.
  • I think there is value thinking where this variable would be used and the resulting code structures people will use, because we may be able to provide some helpful shortcuts to making use of this value.

Here is some useful examples, I already use, but also just tested with thisTiddler;

{{{ [{<thisTiddler>] ||$:/core/ui/Buttons/edit }}} Link to edit the tiddler in which this "filtered transclusion" exists.

Conditional: {{{ [{$:/config/design-mode}match[yes]then<thisTiddler>] ||$:/core/ui/Buttons/edit }}}
  • The second example is conditional on the design-mode
  • I have modified $:/core/ui/Buttons/edit on some occasions such that the tooltip indicates the actual tiddler name it will edit.
  • When in design mode, in some of my development wikis, the links to tiddlers deep within viewTemplates, multi-level transclusions all come alive with an edit icon.
1 Like

Another working example;

<$list filter="[all[current]match<thisTiddler>]">
Display when in list/story
</$list>

<$list filter="[all[current]!match<thisTiddler>]">
Display when Not in list/story
</$list>
  • Although you could test the storyTiddler Variable

The thisTiddler new variable has been merged into TiddlyWiki Pre-release — 5.3.0-prerelease

So, you can study the doc tiddlers and give a try! If you wrote useful examples, please share them here!
Your examples can help to better understand how and where to use the new variables thisTiddler. @telumire has created a nice set of examples above (comparison of thisTiddler, currentTiddler, and storyTiddler)

3 Likes

I am exploring how best to code with the thisTiddler variable, such as in a button tiddler we can now refer to say the caption in the button tiddler rather than the current tiddler eg {{{ [<thisTiddler>get[caption]] }}}.

One Question

Is it just as performant to use <thisTiddler> wherever we need it? or does it take resources to evaluate it,

Such that if we set another variable at the beginning of the tiddler to the listTiddler value eg <$let local-tiddler=<<thisTiddler>>... and only use the <<local-tiddler>> variable going forward is it more or less performant?

Hi @TW_Tones the thisTiddler variable is set whenever the transclude widget is used to transclude a tiddler (as opposed to a variable). The performance of retrieving the value is the same as retrieving any other variable.