Hello!
Is there a filter expression to list all tiddlers in a TOC-“folder” recursively?
for example: in the “Contents” sidebar-tab on tiddlywiki.com, the title of all tiddlers in the Welcome-“folder” including all tiddlers in all “subfolders”?
Cheers
Perhaps something like
<$list filter="[[Welcome]descendants[]]"/>
if you use a third party filter plugin: Yaisog Bonegnasher — a non-linear personal web notebook
It’s not a simple filter expression, but rather a very small recursive \procedure
…
Try this on https://TiddlyWiki.com:
\procedure toc-list(here)
<$set name=exclude filter="[subfilter<exclude>] [<here>]">
<$list filter="[tag<here>] -[enlist<exclude>] +[!has[draft.of]]">
<$link/><br/>
<$macrocall $name=toc-list here=<<currentTiddler>>/>
</$list>
\end
<<toc-list "Welcome">>
Notes:
- The
exclude
variable is used to prevent infinite recursion if a “tag loop” occurs. - For example, if
TiddlerA
tagsTiddlerB
andTiddlerB
tagsTiddlerC
, andTiddlerC
tagsTiddlerA
, then the recursion will continue forever (or until your browser runs out of memory!). - The
exclude
variable starts out empty and then adds the current tiddler (<<here>>
) to keep track of each title that has already been “visited” in the current recursion branch so it won’t be visted again.
enjoy,
-e
@vuk thanks, I’ll take a look at it.
@EricShulman Works perfectly, exactly what I needed!
Just so you know: I need it to limit a search box to a TOC entry. Many thanks!
The code I provided is intended to directly render the resulting list of tiddler titles. However, if you need to “capture” this output in a variable for use in other code (e.g., to “limit a search”), then you will need to make a small adjustment…
Instead of using:
<$link/><br>
to output the titles, you will need to use:
{{{ [<currentTiddler>format:titlelist[]] }}}<br>
to ensure that any titles that contain spaces are properly enclosed within doubled square brackets so that the output forms a valid space-separated, bracketed list of titles. You can then use a $wikify
widget to capture that list, like this:
\procedure toc-list(here)
<$set name=exclude filter="[subfilter<exclude>] [<here>]">
<$list filter="[tag<here>] -[enlist<exclude>] +[!has[draft.of]]">
{{{ [<currentTiddler>format:titlelist[]] }}}<br/>
<$macrocall $name=toc-list here=<<currentTiddler>>/>
</$list>
\end
<$wikify name=tidlist text="""<<toc-list "HelloThere">>""">
... your code goes here ...
</$wikify>
The resulting <<tidlist>>
variable can then be used in your search filter syntax:
[enlist<tidlist>search:text[something]]
I’ve implemented it and it works perfectly; I’m impressed by how skillfully one can program in TiddlyWiki. Thanks again