mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
77b976dd92
686c7b6eb ci(Netlify): specify `HUGO_VERSION` environment variable once da99a356f fix: change heading level e57da3f00 Update taxonomy methods 746172490 Update description of rendered breadcrumb navigation 6bc52fd40 Clarify term dab07dcb0 Fix typo e50fa452a Fix typo 6c1ea83c2 Update template overview page a5dc97845 Clarify the append function a135e52a0 Update GitHub hosting instructions a51bf9f4f Update sections page ed35fc6c4 Update archetypes and glossary 1a4522b3e Format examples a70f20094 Use "hugo new content" to create content 673846ff9 Remove comment b7febf0c5 Fix link 6f6fe2133 Miscellaneous edits 99227dd18 Remove lookup order table from output formats page bc8870657 tools/editors: Add Prettier Plugin for Go Templates 157b169eb Update docs.yaml 1c8f514e0 Update cond function e5f1f8113 Add assumptions to taxonomy and term template lookup order examples 475b406e2 Update postprocess 2d6cb8dfc glossary: Update content type 03b514bac Add descriptions to template lookup order example sections 06678f919 glossary: Fix broken link 4cd505612 Simplify news listing fadb980db Update glossary of terms 491bacd78 Change order of example sections for template lookup order 04b8f39ec Create glossary of terms 12e896bc0 Remove reference to asciidoctor-rouge extension 055f7bb37 Insert missing words 8cd6ac387 Miscellaneous edits 2cbe17f41 Update configuration.md 529615373 Update data-templates.md 853154e65 Update theme 45f08627a resources.getRemote: Fix definition list 29a51dac1 Update docshelper 3bdfe88c6 Remove link to gitter from site footer cacd0e461 Use "map" instead of "dictionary" 704dd5da6 Document the transform.Remarshal template function e8d744951 Populate news section via GitHub releases API 3ff1118c7 Replace docs.json with docs.yaml 7726bbcac Use docs.json to generate default config throughout the site 57dca93df Use docs.json to generate default config for related content 74d5082c7 Add some .RenderShortcodes docs cf5ab5062 netlify: Hugo 0.117.0 420f7aa69 Add all config to docshelper.json git-subtree-dir: docs git-subtree-split: 686c7b6eb182ed335dc94b3a0b80c564f7658380
117 lines
4.4 KiB
Markdown
117 lines
4.4 KiB
Markdown
---
|
|
title: Site variables
|
|
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.
|
|
categories: [variables and parameters]
|
|
keywords: [global,site]
|
|
menu:
|
|
docs:
|
|
parent: variables
|
|
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.
|
|
|
|
## Get the site object from a partial
|
|
|
|
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.
|
|
|
|
## Site variables
|
|
|
|
.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.DisqusShortname
|
|
: a string representing the shortname of the Disqus shortcode as defined in the site configuration.
|
|
|
|
.Site.GoogleAnalytics
|
|
: a string representing your tracking code for Google Analytics as defined in the site configuration.
|
|
|
|
.Site.Home
|
|
: reference to the homepage's [page object](/variables/page/)
|
|
|
|
.Site.IsMultiLingual
|
|
: whether there are more than one language in this site. See [Multilingual](/content-management/multilingual/) for more information.
|
|
|
|
.Site.IsServer
|
|
: a boolean to indicate if the site is being served with Hugo's built-in server. See [`hugo server`](/commands/hugo_server/) 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
|
|
: a string representing the language tag as defined in the site configuration.
|
|
|
|
.Site.LanguagePrefix
|
|
: 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/abslangurl/) and [relLangURL](/functions/rellangurl).
|
|
|
|
.Site.Languages
|
|
: an ordered list (ordered by defined weight) of languages.
|
|
|
|
.Site.LastChange
|
|
: a string representing the date/time of the most recent change to your site. This string is based on the [`date` variable in the front matter](/content-management/front-matter) of your content pages.
|
|
|
|
.Site.Menus
|
|
: all the menus in the site.
|
|
|
|
.Site.Pages
|
|
: array of all content ordered by Date with the newest first. This array contains only the pages in the current language.
|
|
|
|
.Site.RegularPages
|
|
: a shortcut to the *regular* page collection. `.Site.RegularPages` is equivalent to `where .Site.Pages "Kind" "page"`.
|
|
|
|
.Site.Sections
|
|
: top-level directories of the site.
|
|
|
|
.Site.Taxonomies
|
|
: 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).
|
|
|
|
.Site.Title
|
|
: a string representing the title of the site.
|
|
|
|
## Site parameters
|
|
|
|
`.Site.Params` is a container holding the values from the `params` section of your site configuration.
|
|
|
|
### Example: `.Site.Params`
|
|
|
|
The following `config.[yaml|toml|json]` defines a site-wide parameter for `description`:
|
|
|
|
{{< code-toggle file="hugo" >}}
|
|
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" >}}
|
|
<meta name="description" content="{{ if .IsHome }}{{ $.Site.Params.description }}{{ else }}{{ .Description }}{{ end }}" />
|
|
{{< /code >}}
|
|
|
|
[config]: /getting-started/configuration/
|