Unexpected behaviour of a shortcode used in content files to show in-section prev/next links


I’ve almost finished building my first static site with Hugo. Thanks to the documentation and many of the useful discussions here, I’ve managed to find solutions for all requirements I have.

Now there’s only one thing left where I’m stuck:
I’m trying to build an in-section navigation with “Previous” and “Next” links. For each article I would like to have links that lead to either the previous or the next article within the same section.

I can’t use the section’s single.html template to add the links. Due to the varying position of the prev/next links within the articles, I thought I could use a shortcode inside the article’s markdown file to include the functionality. Inside the shortcode I’ve used the variables .NextInSection and .PrevInSection to build the links.

While building and testing the shortcode, I’ve stumbled upon an unexpected behaviour: The variables appear to only be available when I’ve saved the shortcode file at least once while “hugo server” is running.

Here’s the unexpected sequence of events:

  1. I start hugo server --ignoreCache (on a Windows 7 Pro system)
  2. I go to localhost:1313
  3. The prev/next links don’t appear
  4. I just add one line break at the end of my shortcode file and save it
  5. After the live reload the prev/next links appear!

As soon as I restart the hugo server, the prev/next links are gone again - until I save another change to the shortcode file.

The “public” output is also built without the working prev/next links.

I have no idea what I’m doing wrong here. What is it that I’m missing?

Here’s how I use the shortcode inside a section’s article:

Lorem ipsum dolor sit amet, consetetur sadipscing elitr
{{% prev-or-next-in-section %}}
At vero eos et accusam et justo duo dolores et ea rebum.

Here’s the shortcode:

  <ul id="prev-or-next-in-section" class="pager">
    {{if .Page.NextInSection}}
      <li class="next"><a href="{{.Page.NextInSection.Permalink}}">Next</a></li>
      Nothing (could have been "next  ")<br>
    {{if .Page.PrevInSection}}
      <li class="previous"><a href="{{.Page.PrevInSection.Permalink}}">Previous</a></li>
      Nothing (could have been "previous")<br>

In case more context is useful, I’ve created a simple example site structure that contains above code and shows the unexpected behaviour. Since I can’t upload zip archives, I’ve put it in my Dropbox:
(Sorry, I’ve seen others providing examples via Github, but I don’t know how to do Git things yet.)

Does someone see where I make a mistake?

Thanks in advance for any help.