Table of Contents based on tiddler name

Is there a way to create a table of contents based on the tiddler’s title?

I thought it would be helpful to link a number of tiddlers to another summary tiddler, and then have that summary tiddler contain a table of contents. If I change the name of the tiddler, I would like the table of contents to update too. I would think something like the following, but it is not working.

<<toc-selective-expandable !!{{title}}>>

1 Like

You need to use the transclude widget, transcluding a $variable

Every macro, procedure and function internally is a variable. You also need to wrap the toc inside a DIV with the class=“tc-table-of-contents” like so:

<div class="tc-table-of-contents">
<$transclude $variable="toc-selective-expandable" tag={{!!title}}/>
</div>

{{!!title}} also is wikitext shortcut for transclude the <<currentTiddler>>
See: Transclusion in Wikitext

:thinking: This strikes me as an odd deviation from the simplicity of most macros and widgets.

If <<tag>> assumes current tiddler, why shouldn’t <<toc>> and its friends take the current tiddler as their default parameter?

Would there be a cost to allowing the current tiddler title to serve as the home base for the toc macro until/unless specified otherwise?

This is perfect, thank you!

1 Like

Good question. There is no cost. Probably nobody did request it till now. – At least I cannot remember it.

I personally would also like to use it without the wrapper. But since I do create new TOCs very rarely, it was not annoying enough for me to create a PR to change it - in a backwards compatible way

You may raise a GH issue, so it won’t be forgotten.

2 Likes

What if I just wanted to make a list with the current tiddler title?

I tried changing the code with $variable=“list” but it didn’t seem to work.