Table of contents across multiple sections in template

Hi everyone!

I am looking for a proper way how can I add TOC to an already existing page template that consists out of blocks with parameters (below).
I am not sure how do I insert TOC into template, so it would apply to all sections. Should I re-write template or there is another way?

Any guidance is appreciated, thank you!

See part of the template:

{{ define "main" }}

{{with .Params.intro_block_}}
<section class="section">
  <div class="container">
    <div class="row justify-content-center align-items-center">
      <div class="col-lg-5">
        <div class="section-title">
          <h2 class="h1 mb-4">{{ .title | markdownify}}</h2>
          <div class="content pe-0 pe-lg-5">{{.content | markdownify}}</div>
        </div>      
      </div>
      <div class="col-lg-5 mt-5 mt-lg-0 justify-center">
        {{ if .image }}
        {{ if fileExists (add `assets/` .image) }}
        {{$img:= resources.Get (.image) }}
        {{$img:= $img.Resize "1280x webp"}}
        <img loading="lazy" decoding="async" src="{{$img.RelPermalink}}" alt="{{.title}}" class="rounded w-100" width="{{$img.Width}}" height="{{$img.Height}}">
        {{ end }}
        {{ end }}
      </div>
    </div>
  </div>
</section>
{{end}}

{{ with .Params.block_1_}}
<section class="section">
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-lg-10">
        <div class="section-title">
          <h2 class="h1 mb-4">{{ .title | markdownify}}</h2>
          <div class="content pe-0 pe-lg-5">{{.content | markdownify}}</div>
        </div>    
      </div>
    </div>
  </div>
</section>
{{end}}

Solved by adding container row where TOC is now. Now, there is a problem with scope of TOC as it doesn’t retrieve heading from the sections. Will post another question.

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