| 1 |
--- |
| 2 |
title: Weight |
| 3 |
description: Returns the `weight` property of the given menu entry. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: int |
| 9 |
signatures: [MENUENTRY.Weight] |
| 10 |
--- |
| 11 |
|
| 12 |
If you define the menu entry [automatically][], the `Weight` method returns the page's [`Weight`][]. |
| 13 |
|
| 14 |
If you define the menu entry in [front matter][] or in your [project configuration][], the `Weight` method returns the `weight` property, falling back to the page's `Weight`. |
| 15 |
|
| 16 |
In this contrived example, we limit the number of menu entries based on weight: |
| 17 |
|
| 18 |
```go-html-template |
| 19 |
<ul> |
| 20 |
{{ range .Site.Menus.main }} |
| 21 |
{{ if le .Weight 42 }} |
| 22 |
<li><a href="{{ .URL }}">{{ .Name }}</a></li> |
| 23 |
{{ end }} |
| 24 |
{{ end }} |
| 25 |
</ul> |
| 26 |
``` |
| 27 |
|
| 28 |
[`Weight`]: /methods/page/weight/ |
| 29 |
[automatically]: /content-management/menus/#define-automatically |
| 30 |
[front matter]: /content-management/menus/#define-in-front-matter |
| 31 |
[project configuration]: /content-management/menus/#define-in-project-configuration |