Weight
返回给定页面在 front matter 中定义的权重。
Syntax
PAGE.Weight
Returns
int
Page 对象上的 Weight 方法返回给定页面在 front matter 中定义的 权重。
---
title: How to make spicy tuna hand rolls
weight: 42
---+++
title = 'How to make spicy tuna hand rolls'
weight = 42
+++{
"title": "How to make spicy tuna hand rolls",
"weight": 42
}
页面权重控制页面在按权重排序的集合中的位置。使用非零整数分配权重。较轻的项目浮到顶部,而较重的项目沉到底部。未加权或零权重的元素放置在集合的末尾。
虽然很少在模板中使用,但您可以使用以下方式访问值:
{{ .Weight }} → 42