- About Hugo
- Getting Started
- Hugo Modules
-
Content Management
- Content Management Overview
- Organization
- Page Bundles
- Content Formats
- Front Matter
- Build Options
- Page Resources
- Image Processing
- Shortcodes
- Related Content
- Sections
- Content Types
- Archetypes
- Taxonomies
- Summaries
- Links and Cross References
- URL Management
- Menus
- Static Files
- Table of Contents
- Comments
- Multilingual and i18n
- Syntax Highlighting
-
Templates
- Templates Overview
- Introduction
- Template Lookup Order
- Custom Output Formats
- Base Templates and Blocks
- List Page Templates
- Homepage Template
- Section Templates
- Taxonomy Templates
- Single Page Templates
- Content View Templates
- Data Templates
- Partial Templates
- Shortcode Templates
- Local File Templates
- 404 Page
- Menu Templates
- Pagination
- RSS Templates
- Sitemap Template
- Robots.txt
- Internal Templates
- Alternative Templating
- Template Debugging
-
Functions
- Functions Quick Reference
- .AddDate
- .Format
- .Get
- .GetPage
- .HasMenuCurrent
- .IsMenuCurrent
- .Param
- .Render
- .RenderString
- .Scratch
- .Unix
- absLangURL
- absURL
- after
- anchorize
- append
- apply
- base64
- chomp
- complement
- cond
- countrunes
- countwords
- dateFormat
- default
- delimit
- dict
- echoParam
- emojify
- eq
- errorf and warnf
- fileExists
- findRE
- first
- float
- ge
- getenv
- group
- gt
- hasPrefix
- highlight
- hmac
- htmlEscape
- htmlUnescape
- hugo
- humanize
- i18n
- Image Functions
- in
- index
- int
- intersect
- isset
- jsonify
- lang.Merge
- lang.NumFmt
- last
- le
- len
- lower
- lt
- markdownify
- Math
- md5
- merge
- ne
- now
- os.Stat
- partialCached
- path.Base
- path.Dir
- path.Ext
- path.Join
- path.Split
- plainify
- pluralize
- printf
- println
- querify
- range
- readDir
- readFile
- ref
- reflect.IsMap
- reflect.IsSlice
- relLangURL
- relref
- relURL
- replace
- replaceRE
- safeCSS
- safeHTML
- safeHTMLAttr
- safeJS
- safeURL
- seq
- sha
- shuffle
- singularize
- site
- slice
- slicestr
- sort
- split
- string
- strings.Count
- strings.HasSuffix
- strings.Repeat
- strings.RuneCount
- strings.TrimLeft
- strings.TrimPrefix
- strings.TrimRight
- strings.TrimSuffix
- substr
- symdiff
- templates.Exists
- time
- title
- transform.Unmarshal
- trim
- truncate
- union
- uniq
- upper
- urlize
- urls.Parse
- where
- with
- Variables
- Hugo Pipes
- CLI
- Troubleshooting
- Tools
- Hosting & Deployment
- Contribute
- Maintenance
Site Variables
The following is a list of site-level (aka “global”) variables. Many of these variables are defined in your site’s configuration file , 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
function, e.g. site.RegularPages
, which can be handy in partials where the Page
object isn’t easily available.
New in v0.53
.
Site Variables List
- .Site.AllPages
- array of all pages, regardless of their translation.
- .Site.Author
- a map of the authors as defined in the site configuration.
- .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 .
- .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
- .Site.IsMultiLingual
- whether there are more than one language in this site. See 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
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 as defined in the site configuration. This is mostly used to populate the RSS feeds with the right language code.
- .Site.LanguagePrefix
- this can be used to prefix URLs to point to the correct language. It will even work when only one defined language. See also the functions absLangURL and 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 of your content pages. - .Site.Menus
- all of 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. See
.Site.Pages
. - .Site.RegularPages
- a shortcut to the regular page collection.
.Site.RegularPages
is equivalent towhere .Site.Pages "Kind" "page"
. See.Site.Pages
. - .Site.Sections
- top-level directories of the site.
- .Site.Taxonomies
- the taxonomies for the entire site. Also see section Taxonomies elsewhere .
- .Site.Title
- a string representing the title of the site.
The .Site.Params
Variable
.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 param for description
:
baseURL: https://yoursite.example.com/
params:
author: Nikola Tesla
description: Tesla's Awesome Hugo Site
baseURL = 'https://yoursite.example.com/'
[params]
author = 'Nikola Tesla'
description = "Tesla's Awesome Hugo Site"
{
"baseURL": "https://yoursite.example.com/",
"params": {
"author": "Nikola Tesla",
"description": "Tesla's Awesome Hugo Site"
}
}
You can use .Site.Params
in a
partial template
to call the default site description:
<meta name="description" content="{{if .IsHome}}{{ $.Site.Params.description }}{{else}}{{.Description}}{{end}}" />
The .Site.Pages
Variable
.Site.Pages
compared to .Pages
- A regular page is a “post” page or a “content” page.
- A leaf bundle is a regular page.
- A list page can list regular pages and other list pages. Some
examples are: homepage, section pages, taxonomy term (
/tags/
) and taxonomy (/tags/foo/
) pages.- A branch bundle is a list page.
.Site.Pages
- Collection of all pages of the site: regular pages, sections, taxonomies, etc. – Superset of everything!
.Site.RegularPages
- Collection of only regular pages.
The above .Site. ..
page collections can be accessed from any scope in
the templates.
Below variables return a collection of pages only from the scope of the current list page:
.Pages
- Collection of regular pages and only first-level section pages under the current list page.
.RegularPages
- Collection of only regular pages under the
current list page. This excludes regular pages in nested sections/list pages (those are subdirectories with an
_index.md
file. .RegularPagesRecursive
- Collection of all regular pages under a list page. This includes regular pages in nested sections/list pages.
This feature was added in Hugo version 0.68.0
- Note
- From the scope of regular pages,
.Pages
and.RegularPages
return an empty slice.