HUGO
Menu
GitHub 87548 stars Mastodon

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

Last updated: January 1, 0001
Improve this page