我嘗試對收集進行排序時遇到了一個奇怪的行爲。 當我通過收集排序不起作用
{% assign collection = site.collection_name | sort:"weight" %}
排序名稱爲「COLLECTION_NAME」集合是沒有問題的。所有藏品中site.collections
和 同一個集合可以訪問可通過
{% assign collection_to_be_sorted = site.collections[collection_name].docs}
但排序
{% assign collection = collection_to_be_sorted | sort:"weight" %}
導致
Liquid Exception: undefined method `sort' for nil:NilClass in _includes/navigation.html
但是,{{ collection_to_be_sorted.weight }}
存在錯誤。有沒有人有一個想法,爲什麼它不工作?
這很煩人,因爲我想通過所有收集並對它們進行排序。
刪除'從'assign'結束.docs'? –
這不起作用。如果沒有'.docs',我只能得到標籤,目錄等集合屬性。集合中的頁面是'.docs'。我還比較了'site.collection_name'和'site.collections [collection_name] .docs'的輸出,它們是相同的。但是,後者不能排序。 – Ben