IsDefault
- Syntax
- SITE.IsDefault
- Returns
- bool
Usage
The IsDefault method on a Site object reports whether the given site is the default site across all dimensions: language, version, and role. Hugo generates one site for each combination of language, version, and role, as described in the multidimensional content model, and executes your templates once for each site. Use this method to execute a block of code only once per build, regardless of the number of sites.
Examples
This project configuration defines six sites, one for each combination of two languages and three versions:
languages:
de:
label: Deutsch
locale: de-DE
weight: 1
en:
label: English
locale: en-US
weight: 2
versions:
v1.0.0: {}
v2.0.0: {}
v3.0.0: {}
[languages]
[languages.de]
label = 'Deutsch'
locale = 'de-DE'
weight = 1
[languages.en]
label = 'English'
locale = 'en-US'
weight = 2
[versions]
[versions.'v1.0.0']
[versions.'v2.0.0']
[versions.'v3.0.0']
{
"languages": {
"de": {
"label": "Deutsch",
"locale": "de-DE",
"weight": 1
},
"en": {
"label": "English",
"locale": "en-US",
"weight": 2
}
},
"versions": {
"v1.0.0": {},
"v2.0.0": {},
"v3.0.0": {}
}
}
Calling an initialization partial template only once per build, such as to handle one-time build logic or global variable setup:
{{ if site.IsDefault }}
{{ partial "init.html" . }}
{{ end }}With this configuration, Hugo executes the if block only for the English v3.0.0 site. English is the default language because the configuration does not set defaultContentLanguage and includes a language named en. Version v3.0.0 is the default version because the configuration does not set defaultContentVersion, and v3.0.0 is first in descending semantic version order.
