Accessing the title passed into a function?

Can you explain more?

I understand @saqimtiaz’s explanation of why we cannot have a special variable here pointing to the current item at all: we have a list of items and not a single current item.

But I don’t see any explanation of how currentTiddler “already has a use in functions.” Is this something beyond the fact that it’s the name commonly given to the tiddler in which you’re operating, to list items, and to other instances of operating in a specific context? I can’t find anything in the documentation about it.

There is a current tiddler set, either in the story or in a list widget without a variable set. In contrast, as you may recall in tabs, the currentTab is set, not the currentTiddler.

When you use a filter you may generate a list of titles, and if you use one of the filter runs like :filter and :map within them you have the …currentTiddler and currentTiddler variables, sure, but that is a feature of the filter runs.
Otherwise in a filter of any kind you can choose to use [all[current] or [<currentTiddler>] to access the current story tiddler, or that within an “outer list”.

However, if you are instead using a filter like [tag[TableOfContents]... the titles will change once for each tiddler so tagged. If you then feed this to a function eg [addprefix[$:/meta/]] the function treats each input as a separate title, and adds the prefix to each.

\function add.it() [addprefix[$:/meta/]]

<$list filter="[tag[TableOfContents]add.it[]]">

</$list>

If currentTiddler was not changed, this remains available. So lets make use of the currentTiddler from the story in the following;

In the demo tiddler;

\function add.it() [addprefix[$:/meta/]addsuffix[/]addsuffix<currentTiddler>]

<$list filter="[tag[TableOfContents]add.it[]]">

</$list>

The result is each TableOfContents tiddler, with the $:/meta/ prefix and / and currentTiddler Suffix.

  • See current tiddler is still an independent variable
  • Unlike in the filter runs, the currentTiddler variable does not get set to the “current title”. Thats why I don’t want to reuse it.
  • Observe how the function/filter “add.it”, starts without a named title, [all[current] etc, it just starts and acts on each title given to it.

Extended notes

  • Now with our new function.title these filters (in a function return the same thing)
    • [addprefix[$:/meta/]] and [function.title[]addprefix[$:/meta/]]
  • After processing each title it then adds the suffix of currentTiddler, which is the story tiddler. The list widget then lists the titles from the filter (using its currentTiddler variable).

This will not work, using the function.title as a variable. [<function.title>addprefix[$:/meta/]]

  • It will only return the first result.

Ok, I understand how currentTiddler is often set in an outer environment. From what I can tell, though, it has no special meaning within functions, which I what I took you to mean by “it is a variable that already has a use in functions.”

To be clear, or not - yes and no

Inside a function you can have a filter run, such as map, which does give currentTiddler and …currentTiddler " a special meaning.

\function test.it() [tag[TableOfContents]] :map[addprefix[test ]] +[join[ - ]]
\function test.it2() [tag[TableOfContents]] :map[addprefix<currentTiddler>] +[join[ - ]]

<<test.it>>
<<test.it2>>

:laughing:

I think we’re saying the same thing. Functions – as functions – don’t set currentTiddler in any special way, although the wikitext inside a function will use it the same way any other wikitext does.