Adding a shortcut and a command to "Table of Contents"

Hi,

I’m trying to ass a command and a key to the Table of Contents widget without success.

Could someone help me figure out where I have the issue here?

Shouldn’t the following give Table of Contents a command and a shortcut?

 ---
description: Adds a Table of Contents to pages
tags: template
hooks.top:
  where: page !=~ /^Journal[^/]+$/
  command: "Toggle: Table of Contents"
  key: "Ctrl-Alt-t"
  # Show all the way at the top
  order: 0
---

Thanks

Hi,
I think there needs to be a seperate hooks.snippet and a slashCommand like this:

---
description: Adds a Table of Contents to pages
tags: template
hooks.top:
  where: page !=~ /^Journal[^/]+$/
  # Show all the way at the top
  order: 0
hooks.snippet:
  slashCommand: "toc-test"
  command: "Toggle: Table of Contents (Test)"
  key: "Ctrl-Alt-t"
---

Then it works (at least for me)

Thanks @Valentin

I tried it and it works, somehow. I have 2 issues with this:

  • I need to define slashCommand in order for command and key to work, which I am not interested in.
    Maybe I need a different hooks option?

  • Also, the result is that the key shortcut doesn’t “toggle” the TOC but keeps adding more and more, for each key press.
    Did the toggle work for you?

Ah nevermind, you are right. My proposal does not really make sense for toggling the widget. Looks like the command attribute is not yet implemented for the widget hook.

Indeed, there is no such thing as a command nor key binding for live template widgets, because they are activated purely based on the where condition and there’s no real way to implement toggling with that, unless… I suppose you can set an attribute in a page’s frontmatter and hide/show based on that at a page by page basis. That’s a cool hack but probably not really what you are looking for:

In your page:

showTOC: false

In your TOC template where: 'showTOC != false'

What I could hypothetically introduce is a “toggleCommand” or something, which could be checked. That would be highly specific though. And would that toggle be global or per page? Something else?

I was just looking for a typical toggle, like the same one with have for Markdown Preview, but for the TOC.

I don’t mind if it is global or per page.
When i want to switch it off, as normally i have it on by default, I want it for the specific page I am in, maybe because I am working on that page, or rebuilding it entirely, I may need the screen real estate… or whatever it is. But it is due to the present moment where the TOC is bothering me.

If i can toggle with a shortcut, I can just turn it on/off at will regardless of whether it affects a single page or global.