Is there a way to insert a partial just before the footnote section?

I’ve been trying to find a way to insert a partial just before the footnote section but to no avail.

Is there something else that I haven’t found? I understand this is not yet a supported feature–like using .Body .Footnote–so maybe there is hackish way to do this?

I tried using split + index but I can not target the last index, which in an article, that can change.

{{ range $i, $c := split .Content "</div>" }}
  {{ $c | safeHTML }}</div>
  {{ if eq $i 10 }}
    insert content here
  {{ end }}
{{ end }}

It is possible to add some anchor/marker after each content (end of .md file) but that means I have to edit existing posts.

I also considered using the shortcode feature but unfortunately it also mean I have to edit existing content, something I want to avoid.

Is there another way to approach this?

This is partial I want to add just before the footnote section:

{{ $seriescontent := .Site.RegularPages.RelatedIndices . "series" }}
{{ with $seriescontent }}
  <p>{{ i18n "partofseries" }} {{ range ( $.GetTerms "series" ) }}<a href="{{ .Permalink }}">{{ .LinkTitle }}</a>{{ end }}</p>
  <ul>
    {{ range .Reverse }}
    <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
    {{ end }}
  </ul>
{{ end }}

Placing it after {{ .Content }} places it after the footnote section if there is any. Place it before {{ .Content }} is awkward as far as the flow/design of some themes I’m using (this is my last resort).

Thank you!

What is “the footnote section”? Something specific to your theme or the place where the footnotes are printed? If the latter, I don’t think there is a way to find that easily. Maybe something with regular expressions if you know how the section is built and then break it into two parts, but that is above my knowledge. What do you want to insert? Content or something design wise? There is always CSS for easy content stuff.

Footnotes section rendered like this:

<section class="footnotes" role="doc-endnotes">
...
</section>

You can use <section class="footnotes" role="doc-endnotes"> as target using replace

{{- $footnoteHead := `<section class="footnotes" role="doc-endnotes">` -}}
{{- $insertContent := "<div>mycontent</div>" -}}

{{- $joined = print $insertContent $footnoteHead -}}

{{ $Content := replace .Content $footnoteHead $joined 1 }}

{{ $Content | safeHTML }}

2 Likes

It’s the section Hugo, or I think Goldmark, auto generates when you use markdown footnotes, like:

The quick brown fox [^some-footnote] jumps over the lazy dog.

[^some-footnote]: [Wikipedia](https://en.wikipedia.org/ "The quick brown fox")

It’s actually neat, instead of writing “according to this-website, herein quoted, ‘yeah yeah’”, you can just write in your own voice and style and just add a footnote. You can also use it to place all external links at the bottom of the post, similar to the rules in Wikipedia.

For using CSS, unfortunately it’s not possible since I’m inserting a block of HTML with the related feature of Hugo.

Aahh! Brilliant! I didn’t think of replace.

Just to share, if anyone finds this thread in the future, here’s the setup on my end:

In single.html

  • Replace {{ .Content .}} with
{{- $inserthere := `<div role="cover-image-attributions">` -}}
{{- $insertcontent := partial "youronly.one-content-partof.html" . -}}
{{- $joined := print $insertcontent $inserthere -}}
{{- $content := replace .Content $inserthere $joined 1 -}}
{{ $content | safeHTML }}

In my partial youronly.one-content-partof.html

{{- $partofseries := $.Site.RegularPages.RelatedIndices . "series" -}}
{{- with $partofseries -}}
  <aside class="partofseries">
    <p>
      {{ i18n "partofseries" }} {{ range ( $.GetTerms "series" ) }}<a href="{{ .Permalink }}">{{ .LinkTitle }}</a>{{ end }}
    </p>
    <ul>
      {{ range .Reverse }}<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>{{ end }}
    </ul>
  </aside>
{{- end -}}

Note: I used <div role="cover-image-attributions"> since I always add cover image attributions. It is something that is constant on my end.

I noticed, after setting this up, if a content doesn’t have footnotes then there will be no anchor to insert content, <section class="footnotes" role="doc-endnotes"> wouldn’t exist.

If you don’t have something as your last “section” in your content, you’ll have to add some marker, like <span id="contentendmarker"></span> that you can use as an anchor to insert something … with or without the footnotes section.

Side note: There is a feature proposal in GitHub to split {{ .Content }} into .Body and .Footnotes, which is ideal since .TableOfContents is separate from .Content. If this is what you’re looking for, as of this post, it is not yet available.

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