Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table of Contents: support usage outside of Post Content #41173

Open
ZebulanStanphill opened this issue May 19, 2022 · 8 comments
Open

Table of Contents: support usage outside of Post Content #41173

ZebulanStanphill opened this issue May 19, 2022 · 8 comments
Labels
[Block] Table of contents (experimental) Affects the Table of contents Block Needs Dev Ready for, and needs developer efforts [Type] Enhancement A suggestion for improvement.

Comments

@ZebulanStanphill
Copy link
Member

What problem does this address?

Currently, the Table of Contents block only grabs headings from a post that it resides in. But one use case that I think should be supported is putting the block in the post template, but outside the Post Content.

This would necessarily require the use of dynamic rendering, which ironically was just removed from the block in #29739.

Now, the static rendering approach in the aforementioned PR is certainly a lot better for performance, but it's simply not an option for the outside-of-Post-Content use case.

What is your proposed solution?

What if the block automatically used dynamic rendering when outside of the Post Content, but continued to use static rendering otherwise? Would such a thing be possible?

See #32842 (comment) for a bit of prior discussion.

Some questions the implementation needs to answer:

  • Is it possible to determine whether a block is inside the Post Content or not? And if so, how do you do it?
  • How would the "only include headings from current page" option work?
    • Specifically, how do you determine which page of a paginated post is being rendered?
    • What would it look like in the editor, where the whole post is typically rendered?
  • What's the most clean/efficient way to get the blocks of a given post in a format that can provide us all the info we need?
@ZebulanStanphill ZebulanStanphill added [Type] Enhancement A suggestion for improvement. [Block] Table of contents (experimental) Affects the Table of contents Block labels May 19, 2022
@HoffErik-JohnerInst
Copy link

I totally agree with @ZebulanStanphill

I wanted to use the toc in one of my widget areas to create a navigation within my posts. Now it only shows the headings, that are used in my admin-widget-area in all of my posts ^^

I created a workaround via a script that injects all headings dynamically into the menu but that should be the default in my opinion.

@ribaricplusplus
Copy link
Member

Yes please. I don't think it is currently possible to use the Table of Contents block in the Single Post template for example... I'd have to add it to every post. That's just silly. I want to add Table of Contents block to my Single Post template.

@drilichili
Copy link

This is a great Issue, I've ran into the same use-case as @HoffErik-JohnerInst. Would be great if it could be implemented.

@ZebulanStanphill ZebulanStanphill added the Needs Dev Ready for, and needs developer efforts label Jun 7, 2022
@masteradhoc
Copy link
Contributor

+1 on this i would need it in the single post template

@dkjensen
Copy link

dkjensen commented Apr 7, 2023

+1

@richtabor
Copy link
Member

I would expect the table of contents block to always render the headings within the post content, wherever it was added (template, or within single post content itself).

@ZebulanStanphill Is that what you're thinking?

@ZebulanStanphill
Copy link
Member Author

@richtabor Yes, that would be my expectation.

@mrfoxtalbot
Copy link

This is a good opportunity to make the TOC block more robust. When we get down to this, let's also keep in mind the two issues below:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Table of contents (experimental) Affects the Table of contents Block Needs Dev Ready for, and needs developer efforts [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

8 participants