What is the breakdown of the .TableofContents arrary?
For various resons I need to be able to get at individual entries so I can ignore some and use other and in general custom format the table as I please.
As it turns out in the example I have there is no 1,2,3rd level headings just 4th in the table and the full array starts with the markers for the uppers levels, that won’t work looks horrible. Plus I need to not display the first entry.
So I guess I just need to know .TableofContents.What?? to access various levels and entries.
Too…Any way to get hugo/go to display an array’s structure?
While I am on this topic I also do not understand the various page arrays’ contexts very well.
For example
I want to allow end-user editors to thow in a TOC anywhere in the doucment. I have a shortcode {{% toc %}} with corresponding html file
if I put simply
{{ .TableOfContents. }}
into the shortocde file I get this error
ERR: template: shortcodes/toc.html:2:3: executing “shortcodes/toc.html” at <.TableOfContents>: TableOfContents is not a field of struct type *hugolib.ShortcodeWithPage
if I put
{{ Page.TableOfContents. }}
into the shortocde file I get this error
ERR: html/template:shortcodes/toc.html: “shortcodes/toc.html” is an incomplete
if I put {{ .TableOfContents. }} it in my single.html template no problem it renders.
I guess I don’t saavy the scope/context that shortcodes live in. How to I make this work?
.TableOfContents is an HTML string, not an array or tree structure. On my “I should really do this” list of things to do with Hugo, I want to parse it as a tree structure so that we can write better versions of it.
should I make a formal feature request then? Maybe it should be a structure in future versions for the reasons mentioned with some default method for rendering it to html for those who don’t want to mess with it as it is. As it is though is pretty useless to me.
On Fri, Dec 12, 2014 at 2:03 PM, halostatue <discuss@gohugo.io> wrote:
.TableOfContents is an HTML string, not an array or tree structure. On my “I should really do this” list of things to do with Hugo, I want to parse it as a tree structure so that we can write better versions of it.
I’ve tried putting {{ .TableOfContents }} directly in my layouts/_default/single.ace template and that works fine (but of course I don’t want a TOC on every single content page, nor does the top-level template know the best place to put it — that’s why I want to use a shortcode). So… could it be that shortcodes are rendered during page rendering, meaning that some fields of hugolib.Page are still uninitialized?
One could maybe solve your case by delaying the shortcode processing, but you would then get support questions from people using the content and complaining about not seeing the shortcode content … If you can come up with a solution to that, you struck gold!
And the above also does look hacky. Why not put it in a partial?
Do you mean to put it in a partial that I call from the shortcode? That seems to have the same effect. If you mean why don’t I put it in a partial that I call from my template, well, that way I have to put it either before or after the .Content, whereas I’d like to put it in the middle of the content, between the introductory paragraph and the rest of the content.
The template approach could work if there were another method on hugolib.Page that returned “all of the content that isn’t in the summary”… then I could use the following in my single template: