How to get the current page's content of my multipage post to the TOC

I can’t get the content of the current page from my multi-page post to the TOC which is part of the topmost layer of the page.

I followed this thread to create my multi-page post and it works fine.
This is my file structure


post02 is my multi-page post, and it’s rendered in multipage.html. The whole page is rendered like this

baseof.html
[block "main"]multipage.html
[partial]extrabar.html
    [partial]toc.html

The content of the current page is in multipage and is obtained by range $paginator.Pages after $paginator := .Paginate (.RegularPages.ByParam "page_number") 1.
The problem is that it seems the toc is rendered before the real content of the multipage, so I can’t get the real content of my current page to the toc. I found this out by printing the rendering order on the page after failing to save my data to the .Scratch and then getting it in toc. I have no idea how to get the content before the toc is rendered or how to pass the content to the toc and change it after it’s rendered.

[Update] It seems not about the rendering order, but the $paginator? I put the .Page.Scratch.Set outside the $paginator scope and then I can get the content I saved. However, I still can’t solve the problem because the content I want is from the $paginator.
BTW, should I keep updating here or reply to myself before anyone does? I know no edit midstream but what about the start?

1 Like

There are some limitations with the paginated approach to multi-page articles.

I think this is better. The example includes a TOC on each page.

git clone --single-branch -b hugo-forum-topic-40858 https://github.com/jmooring/hugo-testing hugo-forum-topic-40858
cd hugo-forum-topic-40858
hugo server

Thank you! It solved my problem.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.