Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link to next post

Tags:

hugo

My structure in content:

content
|-post
| |-00.md
| |-01.md
| |-02.md
|-about.md

In the single template for the posts I want to have a footer that:

  • is a link to the next post or, if no next post is available
  • is the text "to be continued".

In Pseudo-template-code that means:

{{ if nextpost.exists }} #. becomes nexpost here
  <a href="{{ .Permalink }}">{{ .Title }}</a>
{{ end }}

Where nextpost is currentpost+1


How to create that kind of link?

like image 691
Asqiir Avatar asked May 25 '17 17:05

Asqiir


Video Answer


1 Answers

It sounds like you want the .NextInSection variable. If you use the with function, you can make it work like you want to.

{{ with .NextInSection }}
  <a href="{{ .Permalink }}">{{ .Title }}</a>
{{ end }}

You can use .PrevInSection in a similar way also.

like image 142
Jack Taylor Avatar answered Nov 02 '22 21:11

Jack Taylor