i have toc working for my site with {{ .TableOfContents }} (in single.html) to the first 2 levels. i want it to be only the first level for a particular page. i’ve tried suggestions by chatgpt, huggingchat, and finally perplexity pro and nothing works (either there is no change or there is no toc).
one of the sources perplexity used was veriphor where joe mooring shows how to use fragments for toc.
following perplexity’s directions i did the following:
---
title: Stocks of Interest
date: 2025-05-26T13:15:14-07:00
author: prauthor
description: Prospectus Research by Perplexity Pro.
categories: [erudite]
tags: [stocks]
toc:
startLevel: 1
endLevel: 1
---
created layouts/partials/toc-fragments.html
{{- $startLevel := or (.Param "toc.startLevel" | int) 2 }}
{{- $endLevel := or (.Param "toc.endLevel" | int) 3 }}
{{- $toc := .Fragments.ToHTML $startLevel $endLevel false | safeHTML }}
{{- if $toc }}
{{ $toc }}
{{- end }}
and altered single.html to use the partial
{{ partial "toc-fragments.html" }}
the partial file is being found, but my tocs all vanish site wide unless i use
{{ .TableOfContents }}
adding toc: true changes nothing.
nor does adding any variation of
markup.tableOfContents:
startLevel = 1
endLevel = 1
to frontmatter for that page which i thought would overide my hugo.toml entry:
[markup.tableOfContents]
startLevel = 1 # Start TOC from H2 headers
endLevel = 2 # Include up to H4 headers in TOC
ordered = false # Do not number the items
so am i missing something that is preventing this from working properly?