Better (best?) way to add static content to every page?

I am having a footer where I write something about me. That footer appears on each page. I put the content of the footer in a markdown file in the folder sitewide and add headless: true to the front matter.

Then I load the content via the following snippet:

        {{ with .Site.GetPage "page" "sitewide/" }}
          <div id="authorfooter">
            <h3>{{ .Title }}</h3>
            {{ .Content }}
        {{ end }}

I found that very clever, until it dawned on me, that probably this way leads to Hugo loading x-times that markdown file for x pages (I have about 2000 blogposts). Is there any way to do this via a cached way - but without putting the text for the footer into the theme/layout files?

If you create a partial that includes the code from your post, you can reference that partial in your footer with partialCached. That way it only gets rendered once per website build.

See partialCached and cached partials for more.


Right. I knew that, but it never came into my mind. Thanks :slight_smile: