集合排序不起作用
sorting of collection does not work
我在尝试对集合进行排序时遇到了一个奇怪的行为。
当我按
对名称为 "collection_name" 的集合进行排序时
{% assign collection = site.collection_name | sort:"weight" %}
没有问题。 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 }}
存在。有谁知道为什么它不起作用?
这很烦人,因为我想遍历所有集合并对其进行排序。
在表达式site.collections[collection_name].docs
中,collection_name
被液体当作一个变量。因此,没有返回集合。
试着用引号把它变成一个字符串:
site.collections['collection_name'].docs
我在尝试对集合进行排序时遇到了一个奇怪的行为。 当我按
对名称为 "collection_name" 的集合进行排序时{% assign collection = site.collection_name | sort:"weight" %}
没有问题。 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 }}
存在。有谁知道为什么它不起作用?
这很烦人,因为我想遍历所有集合并对其进行排序。
在表达式site.collections[collection_name].docs
中,collection_name
被液体当作一个变量。因此,没有返回集合。
试着用引号把它变成一个字符串:
site.collections['collection_name'].docs