{% capture the_collection %}{{ page.collection }}{% endcapture %} {% if page.collection %} {% assign document = site[the_collection] | where: "category", page.category %} {% endif %} {% for links in document %} {% if links.title == page.title %} {% unless forloop.first %} {% assign prevurl = prev.url %} {% assign prevtitle = prev.title %} {% endunless %} {% unless forloop.last %} {% assign next = document[forloop.index] %} {% assign nexttitle = next.title %} {% assign nexturl = next.url %} {% endunless %} {% endif %} {% assign prev = links %} {% endfor %}