1

According to the metalsmith-collections docs it supports 'previous/next' links between members of a colleciton:

A Metalsmith plugin that lets you group files together into an ordered collection, like blog posts. That way you can loop over them to generate an index, or add 'next' and 'previous' links between them.

However there is no real example of how this plays out on the template side (I'm using swig, but any example might do).

  • have you seen the [RobinThrift.com](http://www.robinthrift.com) turorial on [metalsmith](http://www.robinthrift.com/posts/metalsmith-part-2-shaping-the-metal/) ? – James Khoury Apr 10 '15 at 00:02
  • Yes, it doesn't cover this specific feature. – Thiago de Mello Bueno Apr 27 '15 at 15:19
  • There is an example of use a collection: http://www.robinthrift.com/posts/metalsmith-part-2-shaping-the-metal/#collections-in-templates and it isn't a stretch to assume that they can be referenced by `this.next` and `this.previous` (while iterating through a collection) – James Khoury Apr 27 '15 at 23:24

2 Answers2

2

I had the same question, and this was the solution I put in my Handlebars template:

{{#if this.previous.path}}
    <a href="{{ link this.previous.path }}">Previous: {{ this.previous.title }}</a>
{{/if}}

{{#if this.next.path }}
    <a href="{{ link this.next.path }}">Next: {{ this.next.title }}</a>
{{/if}}

link is my helper:

Handlebars.registerHelper('link', function(path) {
    return metadata.baseUrl + '/' + path;
});
Damien Sawyer
  • 5,323
  • 3
  • 44
  • 56
James Irwin
  • 1,171
  • 8
  • 21
1

This is how I use next/previous links in my Jade template:-

if previous
    a(href='/'+previous.path) Previous

if next
    a(href='/'+next.path) Next
jtb
  • 139
  • 7