2019-10-21 04:22:28 -04:00
---
2023-07-29 05:15:54 -04:00
title: Site variables
2019-10-21 04:22:28 -04:00
description: Many, but not all, site-wide variables are defined in your site's configuration. However, Hugo provides a number of built-in variables for convenient access to global values in your templates.
2023-07-29 05:15:54 -04:00
categories: [variables and parameters]
2019-10-21 04:22:28 -04:00
keywords: [global,site]
menu:
docs:
2023-05-22 10:43:12 -04:00
parent: variables
2019-10-21 04:22:28 -04:00
weight: 10
weight: 10
aliases: [/variables/site-variables/]
toc: true
---
The following is a list of site-level (aka "global") variables. Many of these variables are defined in your site's [configuration file][config], whereas others are built into Hugo's core for convenient usage in your templates.
2023-07-29 05:15:54 -04:00
## Get the site object from a partial
2020-05-31 06:43:23 -04:00
2022-11-17 10:14:29 -05:00
All the methods below, e.g. `.Site.RegularPages` can also be reached via the global [`site` ](/functions/site/ ) function, e.g. `site.RegularPages` , which can be handy in partials where the `Page` object isn't easily available.
2020-05-31 06:43:23 -04:00
2023-08-30 13:23:47 -04:00
## Site variables
2019-10-21 04:22:28 -04:00
.Site.AllPages
: array of all pages, regardless of their translation.
.Site.BaseURL
: the base URL for the site as defined in the site configuration.
.Site.BuildDrafts
: a boolean (default: `false` ) to indicate whether to build drafts as defined in the site configuration.
.Site.Copyright
: a string representing the copyright of your website as defined in the site configuration.
.Site.Data
: custom data, see [Data Templates ](/templates/data-templates/ ).
.Site.Home
2023-07-29 05:15:54 -04:00
: reference to the homepage's [page object ](/variables/page/ )
2019-10-21 04:22:28 -04:00
.Site.IsMultiLingual
: whether there are more than one language in this site. See [Multilingual ](/content-management/multilingual/ ) for more information.
.Site.Language.Lang
: the language code of the current locale (e.g., `en` ).
.Site.Language.LanguageName
: the full language name (e.g. `English` ).
.Site.Language.Weight
: the weight that defines the order in the `.Site.Languages` list.
.Site.Language
: indicates the language currently being used to render the website. This object's attributes are set in site configurations' language definition.
.Site.LanguageCode
2021-12-08 02:42:31 -05:00
: a string representing the language tag as defined in the site configuration.
2019-10-21 04:22:28 -04:00
.Site.LanguagePrefix
2023-10-20 03:42:39 -04:00
: this can be used to prefix URLs to point to the correct language. It will even work when there is only one defined language. See also the functions [absLangURL ](/functions/urls/abslangurl ) and [relLangURL ](/functions/urls/rellangurl ).
2019-10-21 04:22:28 -04:00
.Site.Languages
: an ordered list (ordered by defined weight) of languages.
.Site.LastChange
2023-10-20 03:42:39 -04:00
: a [time.Time ](https://godoc.org/time#Time ) value representing the date/time of the most recent change to your site.
2019-10-21 04:22:28 -04:00
.Site.Menus
2022-11-17 10:14:29 -05:00
: all the menus in the site.
2019-10-21 04:22:28 -04:00
.Site.Pages
2023-10-20 03:42:39 -04:00
: array of all content ordered by Date with the newest first. This array contains only the pages in the current language.
2019-10-21 04:22:28 -04:00
.Site.RegularPages
2023-08-30 13:23:47 -04:00
: a shortcut to the *regular* page collection. `.Site.RegularPages` is equivalent to `where .Site.Pages "Kind" "page"` .
2019-10-21 04:22:28 -04:00
.Site.Sections
: top-level directories of the site.
.Site.Taxonomies
2023-05-22 10:43:12 -04:00
: the [taxonomies ](/content-management/taxonomies/ ) for the entire site. Also see section [Access taxonomy data from any template ](/variables/taxonomy/#access-taxonomy-data-from-any-template ).
2019-10-21 04:22:28 -04:00
.Site.Title
: a string representing the title of the site.
2023-08-30 13:23:47 -04:00
## Site parameters
2019-10-21 04:22:28 -04:00
`.Site.Params` is a container holding the values from the `params` section of your site configuration.
### Example: `.Site.Params`
2023-07-29 05:15:54 -04:00
The following `config.[yaml|toml|json]` defines a site-wide parameter for `description` :
2019-10-21 04:22:28 -04:00
2023-05-27 10:59:59 -04:00
{{< code-toggle file = "hugo" > }}
2019-10-21 04:22:28 -04:00
baseURL = "https://yoursite.example.com/"
[params]
description = "Tesla's Awesome Hugo Site"
author = "Nikola Tesla"
{{< / code-toggle > }}
You can use `.Site.Params` in a [partial template ](/templates/partials/ ) to call the default site description:
{{< code file = "layouts/partials/head.html" > }}
2023-05-22 10:43:12 -04:00
< meta name = "description" content = "{{ if .IsHome }}{{ $.Site.Params.description }}{{ else }}{{ .Description }}{{ end }}" / >
2019-10-21 04:22:28 -04:00
{{< / code > }}
[config]: /getting-started/configuration/