TOC and title display

I’ve read quicly the differents threads about TOC macro. I don’t think I’ve seen this question:

Is it possible to modifiy the title display in the TOC expandable macro to append a field to it ?

I have tiddlers named A, B, C and their code field set to 1, 1.1, 1.2… And would like to obtain :

1.A
…1.1 B
…1.2 C

The “title display” used by the toc macros is defined by the toc-caption macro in the $:/core/macros/toc shadow tiddler. To add your “code” field content to the display, you can create a custom definition of the toc-caption macro in the tiddler in which your <<toc-selective-expandable>> macro is invoked, like this:

\define toc-caption()
\whitespace trim
<span class="tc-toc-caption tc-tiny-gap-left">
<$set name="tv-wikilinks" value="no">
  <$transclude field="code"/>
  <$transclude field="caption"><$view field="title"/></$transclude>
</$set>
</span>
\end

<<toc-selective-expandable ... >>

Notes:

  • Your customized version of toc-caption is only applied to the tiddler in which it occurs, so it won’t affect any other uses of toc-* macros.

enjoy,
-e

2 Likes

It’s nearly working, but your version doesn’t show the title …

small typo in my solution…

change this:
<$transclude field="code">
to
<$transclude field="code"/>

-e

Hi Eric,
Can we say this overrides the main toc-caption macro? I mean something similar to overriding a method in a base class in OOP?

Yes. “Override” is an accurate term for this technique.

As presented here, the customized version of toc-caption is only applied within the tiddler in which it is defined, making it a “local override”. However, you could make it a “global override”, simply by tagging the tiddler with $:/tags/global.

-e

1 Like