Bolt CMS Content Ordering

07th October 2016

The Bolt documentation as of the beginning of October 2016 suggested using taxonomies in order to sort or order content. This however caused me a few issues when using record.previous() and within my twig templates. You can pass a field name into these functions to use for the ordering however it only works for field names on the content type itself, not for additional fields on related tables, taxonomies for example.

Thankfully there's an easier way of ordering that doesn't seem to be in the main Bolt documentation. You simply add a new field to your content type and set the 'sort' and 'listing_sort' variables to your new field.

    name: Projects
    singular_name: Project
            type: text
            class: large
            group: content
            type: integer
            min: 0
            label: Order
    sort: sortorder
    listing_sort: sortorder

Now within your templates you can easily get the previous, next, first and last records of a particular content type.

{% set previous = record.previous('sortorder') %}

{% set next ='sortorder') %}

{% setcontent projects = 'projects' %}

{% set first = projects|first %}

{% set last = projects|last %}