权重
语法
PAGE.Weight
返回值
int
Page
对象上的 Weight
方法返回前言中定义的给定页面的权重。
content/recipes/sushi.md
---
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