站点
Syntax
PAGE.Sites
Returns
page.Sites
这是一个方便的方法,用来访问.Site.Sites
。
通过以下站点配置:
hugo.
defaultContentLanguage: de
defaultContentLanguageInSubdir: false
languages:
de:
languageCode: de-DE
languageDirection: ltr
languageName: Deutsch
title: Projekt Dokumentation
weight: 1
en:
languageCode: en-US
languageDirection: ltr
languageName: English
title: Project Documentation
weight: 2
defaultContentLanguage = 'de'
defaultContentLanguageInSubdir = false
[languages]
[languages.de]
languageCode = 'de-DE'
languageDirection = 'ltr'
languageName = 'Deutsch'
title = 'Projekt Dokumentation'
weight = 1
[languages.en]
languageCode = 'en-US'
languageDirection = 'ltr'
languageName = 'English'
title = 'Project Documentation'
weight = 2
{
"defaultContentLanguage": "de",
"defaultContentLanguageInSubdir": false,
"languages": {
"de": {
"languageCode": "de-DE",
"languageDirection": "ltr",
"languageName": "Deutsch",
"title": "Projekt Dokumentation",
"weight": 1
},
"en": {
"languageCode": "en-US",
"languageDirection": "ltr",
"languageName": "English",
"title": "Project Documentation",
"weight": 2
}
}
}
使用此模板:
<ul>
{{ range .Sites }}
<li><a href="{{ .Home.Permalink }}">{{ .Title }}</a></li>
{{ end }}
</ul>
可以生成一个链接到每个主页的列表:
<ul>
<li><a href="https://example.org/de/">Projekt Dokumentation</a></li>
<li><a href="https://example.org/en/">Project Documentation</a></li>
</ul>
要呈现一个链接到主语言(第一个)主页的链接:
{{ with .Sites.First }}
<a href="{{ .Home.Permalink }}">{{ .Title }}</a>
{{ end }}
这等同于:
{{ with index .Sites 0 }}
<a href="{{ .Home.Permalink }}">{{ .Title }}</a>
{{ end }}