站点
Syntax
SITE.Sites
Returns
page.Sites
使用以下网站配置:
hugo.
defaultContentLanguage: de
defaultContentLanguageInSubdir: false
languages:
de:
languageCode: de-DE
languageDirection: ltr
languageName: 德语
title: 项目文档
weight: 1
en:
languageCode: en-US
languageDirection: ltr
languageName: 英语
title: 项目文档
weight: 2
defaultContentLanguage = 'de'
defaultContentLanguageInSubdir = false
[languages]
[languages.de]
languageCode = 'de-DE'
languageDirection = 'ltr'
languageName = '德语'
title = '项目文档'
weight = 1
[languages.en]
languageCode = 'en-US'
languageDirection = 'ltr'
languageName = '英语'
title = '项目文档'
weight = 2
{
"defaultContentLanguage": "de",
"defaultContentLanguageInSubdir": false,
"languages": {
"de": {
"languageCode": "de-DE",
"languageDirection": "ltr",
"languageName": "德语",
"title": "项目文档",
"weight": 1
},
"en": {
"languageCode": "en-US",
"languageDirection": "ltr",
"languageName": "英语",
"title": "项目文档",
"weight": 2
}
}
}
此模板:
<ul>
{{ range .Site.Sites }}
<li><a href="{{ .Home.Permalink }}">{{ .Title }}</a></li>
{{ end }}
</ul>
生成一个链接列表,指向每个首页:
<ul>
<li><a href="https://example.org/de/">项目文档</a></li>
<li><a href="https://example.org/en/">项目文档</a></li>
</ul>
要渲染一个链接到主要(第一个)语言的首页:
{{ with .Site.Sites.First }}
<a href="{{ .Home.Permalink }}">{{ .Title }}</a>
{{ end }}
这等效于:
{{ with index .Site.Sites 0 }}
<a href="{{ .Home.Permalink }}">{{ .Title }}</a>
{{ end }}