Table of Contents behavior

121 views
Skip to first unread message

Stefan Schlechter

unread,
Jan 12, 2021, 2:49:24 AM1/12/21
to TiddlyWiki
Hello,

I would like to expand the next level of entries by clicking on title in TOC ( as it is by clicking on '>') instead of opening the tiddler.

TOC behavior.jpg

How can I archieve that?

Thanks
Stefan

clutterstack

unread,
Jan 12, 2021, 4:55:47 PM1/12/21
to TiddlyWiki
Hi Stefan,

It looks like you'd like to modify the behaviour of the toc-selective-expandable macro. The necessary changes for this particular case would be contained within the toc-linked-selective-expandable-body macro. Both are defined in $:/core/macros/toc.

You'd need to redefine (override) toc-linked-selective-expandable-body to:

1) remove the tiddler link
2) display the tiddler's caption/title within the fold/unfold button, for tiddlers that have more tiddlers downstream in the ToC, and
3) display the tiddler's caption/title by itself for tiddlers that have nothing below them in the ToC hierarchy. (If you wanted, you could make just these captions tiddler links)

I suggest making a new macro tiddler (tag it with $:/tags/Macro) with something like the following in it. I've highlighted (I think) all the changes I made. Obviously anything that's commented out could just be removed.

\define toc-linked-selective-expandable-body(tag,sort:"",itemClassFilter,exclude,path)
<$qualify name="toc-state" title={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix<currentTiddler>] }}}>
  <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item-selected" value="toc-item" >
    <li class=<<toc-item-class>>>
      <!--<$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}> -->
          <$list filter="[all[current]tagging[]$sort$limit[1]]" variable="ignore" emptyMessage="<$button class='tc-btn-invisible'>{{$:/core/images/blank}} <<toc-caption>></$button>">
          <$reveal type="nomatch" stateTitle=<<toc-state>> text="open">
            <$button setTitle=<<toc-state>> setTo="open" class="tc-btn-invisible tc-popup-keep">
              {{$:/core/images/right-arrow}}<<toc-caption>>
            </$button>
          </$reveal>
          <$reveal type="match" stateTitle=<<toc-state>> text="open">
            <$button setTitle=<<toc-state>> setTo="close" class="tc-btn-invisible tc-popup-keep">
              {{$:/core/images/down-arrow}}<<toc-caption>>
            </$button>
          </$reveal>
        </$list>
       <!-- <<toc-caption>> -->
      <!--</$link> -->

      <$reveal type="match" stateTitle=<<toc-state>> text="open">
        <$macrocall $name="toc-selective-expandable" tag=<<currentTiddler>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> exclude=<<__exclude__>> path=<<__path__>>/>
      </$reveal>
    </li>
  </$set>
</$qualify>
\end


The definition of toc-caption can be found at the top of $:/core/macros/toc.

Hope that helps,
Chris

Stefan Schlechter

unread,
Jan 13, 2021, 2:02:13 AM1/13/21
to TiddlyWiki
Hi Chris,

thanks for feedback.

I've implemented your mentioned changesabove  -> that will remove all links - also from the last level of TOC 'Story 1, Story 2 etc.'

How can this be done:
3) display the tiddler's caption/title by itself for tiddlers that have nothing below them in the ToC hierarchy. (If you wanted, you could make just these captions tiddler links)

Thanks
Stefan

PMario

unread,
Jan 13, 2021, 5:55:56 AM1/13/21
to TiddlyWiki
Hi,
Search for the field: toc-link: no parameter
IMO there is no need to change the macro code.
-m

clutterstack

unread,
Jan 13, 2021, 10:38:44 AM1/13/21
to TiddlyWiki
D'oh! I'd say there's no shame in being out-TWed by Mario, but this is actually demonstrated in the tiddlywiki.com tiddler "Example Table of Contents: Selectively Expandable", where the tiddler "SecondThree" has the toc-link: no field and works great. So mea culpa for assuming how the rest of the macro would handle things. Sorry, Stefan. Sorry, Mario!

Best,
Chris

Stefan Schlechter

unread,
Jan 13, 2021, 1:48:57 PM1/13/21
to TiddlyWiki
Yes - that's it!
Thanks to Mario and Chris

Greetings,
Stefan
Reply all
Reply to author
Forward
0 new messages