How to add a link back to the original tid in toc-tabbed-external-nav view?

Hi, I often use macro toc-tabbed-external-nav. It is great! But when you want to modify one tid, you need to copy the tid name and search for it, then open it and edit. Seems a little boring to do so much work. So I want to know how to add a link in the right panel for current open tid, which can be clicked and open the tid?
I check the macros but I have no clue about how to modify it.

\define toc-tabbed-internal-nav(tag,sort:"",selectedTiddler:"$:/temp/toc/selectedTiddler",unselectedText,missingText,template:"")
<$linkcatcher to=<<__selectedTiddler__>>>
  <$macrocall $name="toc-tabbed-external-nav" tag=<<__tag__>> sort=<<__sort__>> selectedTiddler=<<__selectedTiddler__>> unselectedText=<<__unselectedText__>> missingText=<<__missingText__>> template=<<__template__>>/>
</$linkcatcher>
\end

@Ori you can actually modify the toc-tabbed-external-nav to include a link or button, or allow editing inside it, but I like the idea you have as well.

This is somewhat similar; it show the last/latest tiddler in the history in the sidebar;

last-tiddler.json (504 Bytes)

<$tiddler tiddler={{$:/HistoryList!!current-tiddler}}>
   {{||$:/PSaT/button/copy-text}} {{||$:/PSaT/button/copy-title}} {{||$:/core/ui/Buttons/edit}} {{||$:/PSaT/button/copy-title-transclude}} {{||$:/PSaT/button/copy-title-link}} <$link/>
</$tiddler>
  • Ignore the button transcludes, it uses them if available.
  • See how the tiddler title is found in {{$:/HistoryList!!current-tiddler}}?
  • toc-tabbed-external-nav uses $:/temp/toc/selectedTiddler

So try a modified version (clone $:/PSaT/last-tiddler)

<$tiddler tiddler={{$:/temp/toc/selectedTiddler}}>
   {{||$:/PSaT/button/copy-text}} {{||$:/PSaT/button/copy-title}} {{||$:/core/ui/Buttons/edit}} {{||$:/PSaT/button/copy-title-transclude}} {{||$:/PSaT/button/copy-title-link}} <$link/>
</$tiddler>

last-toc-nav.json (500 Bytes)

Perhaps I could make a button to shove the title into $:/temp/search in the sidebar as well?

The original button above comes from an unpublished collection copy-tools-text-title-transclusion-link.json (10.1 KB)
discussed recently Wanted: editortoolbar button that grabs title of current tiddler and wraps it - #14 by TW_Tones

You know when you sweat over a solution, come here to post it, and the forum recommends another post as possibly related?

So, here’s a solution for a slight variation on OP’s challenge – a template-based toc – in case it’s useful to anyone else.

As OP noted, toc-tabbed-external-nav doesn’t tend to include a way to pop out to the original tiddler for editing. Especially if what you see is captions along the side, it can be a nuisance to get to the original! One solution is to modify the macro itself, as noted above.

Great for a “vanilla” toc, but… what if the contents of your toc-tabbed-external-nav are using a special template tiddler?? What if this template also gets used in standalone tiddlers? I didn’t want an ugly self-link showing up when the template was being used outside the toc-framing… (For a while, I kept trying to hide the self-link using a reveal match condition based on currentTab, but currentTab is… NOT what toc-tabbed-external-nav uses! :expressionless: )

So, I dug into the toc core, found a bit of relevant code, and cooked up this snippet. If you find yourself in the rare position of having exactly this challenge, just pop this at the top of your desired template:

<$reveal type="match" default={{{ [<currentTiddler>] }}} text={{{[<__selectedTiddler__>get[text]]}}}>
@@float:right;<$link>↗️ </$link>@@
</$reveal>

(Sorry my :arrow_upper_right: doesn’t display properly inside the code section here. Obviously, use whatever visual cue you like in that position.)

1 Like

Edit: just realized OP’s question is about internal TOC. My post only works for external. I should have read the thread more carefully.

I am too paranoid to modify the $:/core/macros/toc tiddler directly. I made a copy to a tiddler called TocExternalNavWithTitleLinks. I only changed the <h1>contents</h1> to include a link to the tiddler, but still show the caption:

    <div class="tc-tabbed-table-of-contents-content">
        <$reveal stateTitle=<<__selectedTiddler__>> type="nomatch" text="">
          <$transclude mode="block" tiddler=<<__template__>>>
            <!-- ORIGINAL: <h1><<toc-caption>></h1> -->
            <!-- CHANGED TO: -->
            <h1><$link to=<<currentTiddler>> ><<toc-caption>></$link></h1>
            <$transclude mode="block">$missingText$</$transclude>
          </$transclude>
        </$reveal>
        <$reveal stateTitle=<<__selectedTiddler__>> type="match" text="">
          $unselectedText$
        </$reveal>
      </div>

Then in my Table of Contents tiddler:

\import [title[TocExternalNavWithTitleLinks]]

<<toc-tabbed-external-nav>>

Now the titles shown are links to those tiddlers.

I hope this helps. I am quite new to tiddlywiki, so I cannot compare the advantages/disadvantages of this vs other methods, nor can I predict potential complications resulting from this method.

You don’t actually need to make a modified version of $:/core/macros/toc… and you can omit the \import pragma.

All you need to do is to define a LOCAL version of the <<toc-caption>> macro, and then call <<toc-tabbed-external-nav>>, like this:

\define toc-caption()
\whitespace trim
<$let tv-wikilinks="no">
<span class="tc-toc-caption tc-tiny-gap-left">
  <$link><$transclude field="caption"><$view field="title"/></$transclude></$link>
</span>
</$let>
\end
<<toc-tabbed-external-nav>>
  • Since you are linking to the currentTiddler value, you don’t need to specify it in the $link widget… it will be applied by default when there is no to=... parameter
  • The custom toc-caption definition is only applied within the tiddler in which it is defined, so it only affects that instance of toc-tabbed-external-nav

enjoy,
-e

1 Like

I copied your provided code and fixed the </$link, but it did not work for me. The titles are regular text, same as default. Are there other settings or code that makes it work for you?

ohhh! I see the problem…

You wanted to change the display of the tiddler title within the tc-tabbed-table-of-contents-content so that the tiddler title shown there would be a link.

To make my solution work for the content title, just remove the <$let tv-wikilinks="no">, like this:

\define toc-caption()
\whitespace trim
<span class="tc-toc-caption tc-tiny-gap-left">
  <$link><$transclude field="caption"><$view field="title"/></$transclude></$link>
</span>
\end

-e

2 Likes

Thanks! That worked for external nav. Much simpler than my solution. Having some time to consider it, I have decided to define these marcos locally since I only plan to use them in one tiddler. Thanks for pointing out that I could do that.

To make it work with internal nav, I had to edit the toc-tabbed-internal-nav macro and add a new one that I called NavigateToIfMatchesTitle.

\define NavigateToIfMatchesTitle()
<%if [<event-navigateTo>match{$:/temp/toc/selectedTiddler!!text}] %>
  <$action-navigate $to=<<event-navigateTo>> />
<%else%>
  <!-- Looks like there is not a way to propagate messages after they have been caught,
which is what needs to happen here. Instead, manually recreate the action.
https://github.com/TiddlyWiki/TiddlyWiki5/issues/6493
  -->
  <$action-setfield $tiddler=<<__selectedTiddler__>> text=<<event-navigateTo>> />
<%endif%>
\end

\define toc-tabbed-internal-nav(tag,sort:"",selectedTiddler:"$:/temp/toc/selectedTiddler",unselectedText,missingText,template:"",exclude)
\whitespace trim
<$let __tag__={{{ [<__tag__>is[blank]then<currentTiddler>else<__tag__>] }}}>
  <!-- CHANGED: linkcatcher replaced with messagecatch and custom macro. -->
  <$messagecatcher $tm-navigate=<<NavigateToIfMatchesTitle>> >
    <$macrocall $name="toc-tabbed-external-nav" tag=<<__tag__>> sort=<<__sort__>> selectedTiddler=<<__selectedTiddler__>> unselectedText=<<__unselectedText__>> missingText=<<__missingText__>> template=<<__template__>> exclude=<<__exclude__>> />
  </$messagecatcher>
</$let>
\end

Explanation:

The <<__selectedTiddler__>>:text field holds the clicked link title. The view shows the contents of the tiddler that has that title.

So when a user clicks the link in the left navigation tree, the <<__selectedTiddler__>>:text is updated to the new title, and the view updates to show the text of the tiddler with that title.

When a user clicks on a link within the view, the messagecatcher uses NavigateToIfMatchesTitle to check if that tiddler is already the one being viewed. If yes, then the tiddler will be opened separately. If the link is to a different tiddler, then it updates <<__selectedTiddler__>>:text field. The view automatically updates.

Copy of @EricShulman’s solution for the sake of completeness:

\define toc-caption()
\whitespace trim
<span class="tc-toc-caption tc-tiny-gap-left">
  <$link><$transclude field="caption"><$view field="title"/></$transclude></$link>
</span>
\end

Putting all of these macros together allows toc-tabbed-internal-nav, but you can click on the title to follow that link and open the tiddler separately.