site
- Syntax
- site
- Returns
- page.siteWrapper
Usage
The site function returns the Site object of the site being rendered, accessible from any context.
To simplify your templates, use the global site function regardless of whether the current Site object is in context.
A partial template receives only the data passed to it. With the global site function, you can access the Site object within a partial template without passing the Page object:
{{ partial "foo.html" (dict "color" "red") }}{{ site.Title }}
{{ .color }}Examples
This example shows a common pitfall and how to avoid it.
With this project configuration:
languages:
de:
title: Projekt Dokumentation
weight: 1
en:
title: Project Documentation
weight: 2
[languages]
[languages.de]
title = 'Projekt Dokumentation'
weight = 1
[languages.en]
title = 'Project Documentation'
weight = 2
{
"languages": {
"de": {
"title": "Projekt Dokumentation",
"weight": 1
},
"en": {
"title": "Project Documentation",
"weight": 2
}
}
}
And this code in the home template:
{{ range hugo.Sites }}
{{ site.Title }}
{{ end }}The rendered output of the English home page is:
Project Documentation
Project DocumentationIn the example above, the global site function accesses the Site object of the site being rendered, not the Site object of the iterated sites. Use the dot to access the iterated sites:
{{ range hugo.Sites }}
{{ .Title }}
{{ end }}