Weight

Weight 方法在 Page 物件上返回給定頁面的 權重,該權重是由前置資料中定義的。

以下是前置資料範例:

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