Skip to content

Instantly share code, notes, and snippets.

@edwardhorsford
Created September 7, 2018 21:40
Show Gist options
  • Save edwardhorsford/370a4060a5a6dcd92e687fc824c5cdc5 to your computer and use it in GitHub Desktop.
Save edwardhorsford/370a4060a5a6dcd92e687fc824c5cdc5 to your computer and use it in GitHub Desktop.
Hacky next / previous code
{% set currentProjectIndex = 0 %}
{% set countOfProjects = collections.design.length %}
{% for project in collections.design %}
{% if project.url == page.url %}
{% set currentProjectIndex = loop.index0 %}
{% endif %}
{% endfor %}
{% set previousProjectIndex = currentProjectIndex - 1 %}
{% set nextProjectIndex = currentProjectIndex + 1 %}
{% set previousProject = collections.design[previousProjectIndex] %}
{% set nextProject = collections.design[nextProjectIndex] %}
{% if previousProject %}
<p>Previous project: <a href="{{ previousProject.url | url }}" class="">{{ previousProject.data.title }}</a></h2>
{% endif %}
{% if nextProject %}
<p>Next project: <a href="{{ nextProject.url | url }}" class="">{{ nextProject.data.title }}</a></h2>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment