sorting of collection does not work

677 views Asked by At

I have encountered a strange behaviour when I try to sort a collection. When I sort a collection with name "collection_name" by

{% assign collection = site.collection_name | sort:"weight" %}

there is no problem. All collections are available in site.collections and the same collection can be accessed via

{% assign collection_to_be_sorted = site.collections[collection_name].docs}

but sorting

{% assign collection = collection_to_be_sorted | sort:"weight" %}

leads to the error

Liquid Exception: undefined method `sort' for nil:NilClass in _includes/navigation.html

However, {{ collection_to_be_sorted.weight }} exists. Does anyone have an idea why it doesn't work?

This is quite annoying because I want to go through all collections and sort them.

1

There are 1 answers

2
David Jacquel On BEST ANSWER

In the expression site.collections[collection_name].docs, collection_name is treated like a variable by liquid. So, no collection is returned.

Try to quote it to make it a string :

site.collections['collection_name'].docs