Add template logic between content and its footnotes

Thanks, this is great!

There is just on thing missing in your code: when you split .Content matching the footnotes opening tag (<section class="footnotes" role="doc-endnotes">), the pattern will not be in the splitted string.

So, for reference, the working solution is:

<!-- store the beginning of the footnotes specific HTML generated by the Markdown processor into a variable -->
{{ $footnotes_tag:= `<section class="footnotes" role="doc-endnotes">` }}

{{ if strings.Contains .Content $footnotes_tag }}

  <!-- split content and store the result into a variable -->
  {{ $split := split .Content $footnotes_tag }}

  <!-- render content before footnotes -->
  {{ index $split 0 | safeHTML }}

  <!--
    Add template logic here!
  -->
  
  <!-- render footnotes -->
  {{ $footnotes_tag | safeHTML }}{{ index $split 1 | safeHTML }}

{{ else }}
  {{ .Content }}
{{ end }}
1 Like