Count Table of Contents items

I want to display ToC, if there are 3 or more items, but it doesn’t work as it should be

        {{- $tocno := .TableOfContents | findRE `<li>` | len -}}

        {{- if ge $tocno 3 }}

        {{ .TableOfContents }}

        {{ end -}}
1 Like

What does that mean? Do you get an error, do you get a TOC although you don’t want one, do you get no TOC although you want one? Something else happening?

sometimes Table of Contents appears sometimes, even number of li is greater than 3

Older posts content is not in Markdown, but in html that’s why builded hugo’s ToC is not working.

guess the best for the html pages then is using reSubMatch on rawContent and generate the toc yourself