6

我正在尝试在菜单中订购项目,但它不适合我。我尝试按照他们的文档进行操作,但它根本不起作用。

在我的标题中:

      {{ range .Site.Data.Menu }}
      <li>

        <a href="{{ .URL | absURL }}"
        {{ if and ( isset . "Title" ) ( ne .Title "" ) }} title="{{ .Title }}"{{ end }}>

        {{ if and ( isset . "IconClass" ) ( ne .IconClass "" )  }}
            <i class="fa {{ .IconClass }}"></i>
        {{ end }}

        {{ .Name }}
        </a>
      </li>
      {{ end }}

菜单.toml

[home]
    Name = "Home"
    Title = "Home"
    URL = "/home"
    weight = 1

[apparatus]
    Name = "Apparatus"
    URL = "/apparatus"
    weight = 2

[deliveries]
    Name = "Deliveries"
    URL = "/deliveries"
    weight = 3

[command]
    Name = "Command"
    URL = "/command"
    weight = 4

[ambulance]
    Name = "Ambulance"
    URL = "/ambulance"
    weight = 5

[service]
    Name = "Service"
    URL = "/service"
    weight = 6

[about]
    Name = "about"
    URL = "/about"
    weight = 7

[contact]
    Name = "Contact"
    URL = "/contact"
    weight = 8

菜单以看似随机的顺序结束。我如何按照我想要的方式订购它们?

4

3 回答 3

5

权重是 Hugo 中菜单的默认排序。下面的一些变化:

{{ range .Site.Data.Menu.Sort }}
{{ range .Site.Data.Menu.ByName }}
{{ range .Site.Data.Menu.ByName.Reverse }}
{{ range .Site.Data.Menu.ByName.Limit 10 }}
{{ range .Site.Data.Menu.ByWeight }}
于 2016-04-30T15:46:57.970 回答
4

我遇到了同样的问题,并通过使用负数作为权重属性来解决它。

于 2016-02-28T13:41:15.740 回答
4

换行:

{{ range .Site.Data.Menu }}

经过:

{{ range sort .Site.Data.Menu "Weight"}}

这为我解决了问题。

于 2016-03-04T18:27:43.367 回答