hugo/docs/content/templates/variables.md
Anthony Fok b3bd71fec9 Update Hugo docs with the initialisms suggested by golint
In particular:

 * .Url → .URL (for node, menu and paginator)
 * .Site.BaseUrl → .Site.BaseURL
 * getJson → getJSON
 * getCsv → getCSV
 * safeHtml → safeHTML
 * safeCss → safeCSS
 * safeUrl → safeURL

Continued effort in fixing #959.
2015-03-18 11:30:37 +01:00

6.8 KiB

aliases date linktitle menu next prev title weight
/doc/variables/
/layout/variables/
2013-07-01 Variables
main
parent
layout
/templates/content /templates/functions Template Variables 20

Hugo makes a set of values available to the templates. Go templates are context based. The following are available in the context for the templates.

Page Variables

The following is a list of most of the accessible variables which can be defined for a piece of content. Many of these will be defined in the front matter, content or derived from file location.

See also: Scratch for page-scoped writable variables.

.Title The title for the content.
.Content The content itself, defined below the front matter.
.Summary A generated summary of the content for easily showing a snippet in a summary view. Note that the breakpoint can be set manually by inserting <!--more--> at the appropriate place in the content page. See Summaries for more details.
.Truncated A boolean, true if the .Summary is truncated. Useful for showing a "Read more..." link only if necessary. See Summaries for more details.
.Description The description for the content.
.Keywords The meta keywords for this content.
.Date The date the content is associated with.
.PublishDate The date the content is published on.
.Type The content type (e.g. post).
.Section The section this content belongs to.
.Permalink The Permanent link for this page.
.RelPermalink The Relative permanent link for this page.
.LinkTitle Access when creating links to this content. Will use linktitle if set in front matter, else title.
.Taxonomies These will use the field name of the plural form of the taxonomy (see tags and categories below).
.RSSLink Link to the taxonomies' RSS link.
.TableOfContents The rendered table of contents for this content.
.Prev Pointer to the previous content (based on pub date).
.Next Pointer to the following content (based on pub date).
.PrevInSection Pointer to the previous content within the same section (based on pub date)
.NextInSection Pointer to the following content within the same section (based on pub date)
.FuzzyWordCount The approximate number of words in the content.
.WordCount The number of words in the content.
.ReadingTime The estimated time it takes to read the content in minutes.
.Weight Assigned weight (in the front matter) to this content, used in sorting.
.IsNode Always false for pages.
.IsPage Always true for page.
.Site See [Site Variables]({{< relref "#site-variables" >}}) below.
.Hugo See [Hugo Variables]({{< relref "#hugo-variables" >}}) below.

Page Params

Any other value defined in the front matter, including taxonomies, will be made available under .Params. Take for example I'm using tags and categories as my taxonomies. The following would be how I would access them:

  • .Params.tags
  • .Params.categories

All Params are only accessible using all lowercase characters.

Node Variables

In Hugo, a node is any page not rendered directly by a content file. This includes taxonomies, lists and the homepage.

See also: Scratch for global node variables.

.Title The title for the content.
.Date The date the content is published on.
.Permalink The Permanent link for this node
.URL The relative URL for this node.
.Ref(ref) Returns the permalink for ref. See [cross-references]({{% ref "extras/crossreferences.md" %}}). Does not handle in-page fragments correctly.
.RelRef(ref) Returns the relative permalink for ref. See [cross-references]({{% ref "extras/crossreferences.md" %}}). Does not handle in-page fragments correctly.
.RSSLink Link to the taxonomies' RSS link.
.Data The data specific to this type of node.
.IsNode Always true for nodes.
.IsPage Always false for nodes.
.Site See [Site Variables]({{< relref "#site-variables" >}}) below.
.Hugo See [Hugo Variables]({{< relref "#hugo-variables" >}}) below.

Site Variables

Also available is .Site which has the following:

.Site.BaseURL The base URL for the site as defined in the site configuration file.
.Site.Taxonomies The taxonomies for the entire site. Replaces the now-obsolete .Site.Indexes since v0.11.
.Site.LastChange The date of the last change of the most recent content.
.Site.Pages Array of all content ordered by Date, newest first. Replaces the now-deprecated .Site.Recent starting v0.13.
.Site.Params A container holding the values from the params section of your site configuration file. For example, a TOML config file might look like this:

baseurl = "http://yoursite.example.com/"

[params]
  description = "Tesla's Awesome Hugo Site"
  author = "Nikola Tesla"

.Site.Sections Top level directories of the site.
.Site.Pages All of the content pages of the site.
.Site.Files All of the source files of the site.
.Site.Menus All of the menus in the site.
.Site.Title A string representing the title of the site.
.Site.Author A map of the authors as defined in the site configuration.
.Site.LanguageCode A string representing the language as defined in the site configuration.
.Site.DisqusShortname A string representing the shortname of the Disqus shortcode as defined in the site configuration.
.Site.Copyright A string representing the copyright of your web site as defined in the site configuration.
.Site.LastChange A string representing the last time content has been updated.
.Site.Permalinks A string to override the default permalink format. Defined in the site configuration.
.Site.BuildDrafts A boolean (Default: false) to indicate whether to build drafts. Defined in the site configuration.
.Site.Data Custom data, see Data Files.

Hugo Variables

Also available is .Hugo which has the following:

.Hugo.Generator Meta tag for the version of Hugo that generated the site. Highly recommended to be included by default in all theme headers so we can start to track Hugo usage and popularity. e.g. <meta name="generator" content="Hugo 0.13" />
.Hugo.Version The current version of the Hugo binary you are using e.g. 0.13-DEV
.Hugo.CommitHash The git commit hash of the current Hugo binary e.g. 0e8bed9ccffba0df554728b46c5bbf6d78ae5247
.Hugo.BuildDate The compile date of the current Hugo binary formatted with RFC 3339 e.g. 2002-10-02T10:00:00-05:00