If you define the menu entry automatically, the Weight
method returns the page’s Weight
.
如果您自动定义菜单项,该Weight方法将返回页面的Weight。
If you define the menu entry [in front matter] or [in site configuration], the Weight
method returns the weight
property, falling back to the page’s Weight
.
如果你在前言或站点配置中定义菜单项,则该Weight方法返回该weight属性,并回退到页面的Weight。
In this contrived example, we limit the number of menu entries based on weight:
在这个虚构的例子中,我们根据重量限制菜单条目的数量:
<ul>
{{ range .Site.Menus.main }}
{{ if le .Weight 42 }}
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
{{ end }}
</ul>