2013-07-06 23:36:30 +00:00
---
2014-05-29 22:42:05 +00:00
aliases:
- /doc/variables/
- /layout/variables/
date: 2013-07-01
linktitle: Variables
2014-04-23 07:00:11 +00:00
menu:
main:
2014-05-29 22:42:05 +00:00
parent: layout
next: /templates/content
prev: /templates/functions
title: Template Variables
weight: 20
2013-07-08 21:57:01 +00:00
---
2013-07-04 15:32:55 +00:00
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.
2013-08-17 12:34:25 +00:00
## Page Variables
2014-01-22 01:05:26 +00:00
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.
2013-08-08 23:13:03 +00:00
**.Title** The title for the content.< br >
2014-01-22 01:05:26 +00:00
**.Content** The content itself, defined below the front matter.< br >
2014-10-17 01:00:09 +00:00
**.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 < code > < !- - more- - > < / code > at the appropriate place in the content page.< br >
2013-07-04 15:32:55 +00:00
**.Description** The description for the content.< br >
**.Keywords** The meta keywords for this content.< br >
2014-05-29 05:00:06 +00:00
**.Date** The date the content is associated with.< br >
**.PublishDate** The date the content is published on.< br >
2014-11-25 08:07:18 +00:00
**.Type** The content [type ](/content/types/ ) (e.g. post).< br >
**.Section** The [section ](/content/sections/ ) this content belongs to.< br >
2013-07-04 15:32:55 +00:00
**.Permalink** The Permanent link for this page.< br >
2013-10-25 22:37:53 +00:00
**.RelPermalink** The Relative permanent link for this page.< br >
2014-11-25 08:07:18 +00:00
**.LinkTitle** Access when creating links to this content. Will use linktitle if set in front-matter, else title.< br >
**.Taxonomies** These will use the field name of the plural form of the index (see tags and categories above).< br >
**.RSSLink** Link to the indexes' rss link.< br >
**.TableOfContents** The rendered table of contents for this content.< br >
**.Prev** Pointer to the previous content (based on pub date).< br >
**.Next** Pointer to the following content (based on pub date).< br >
2014-04-18 07:23:13 +00:00
**.PrevInSection** Pointer to the previous content within the same section (based on pub date)< br >
**.NextInSection** Pointer to the following content within the same section (based on pub date)< br >
2014-01-22 01:05:26 +00:00
**.FuzzyWordCount** The approximate number of words in the content.< br >
**.WordCount** The number of words in the content.< br >
**.ReadingTime** The estimated time it takes to read the content in minutes.< br >
**.Weight** Assigned weight (in the front matter) to this content, used in sorting.< br >
2014-08-20 01:27:13 +00:00
**.IsNode** Always false for pages.< br >
**.IsPage** Always true for page.< br >
2014-11-25 08:07:18 +00:00
**.Site** See site variables below.< br >
2013-07-04 15:32:55 +00:00
2014-01-22 01:05:26 +00:00
## Page Params
Any other value defined in the front matter, including indexes will be made available under `.Params` .
2013-07-04 15:32:55 +00:00
Take for example I'm using tags and categories as my indexes. The following would be how I would access them:
2014-01-22 01:05:26 +00:00
**.Params.tags** < br >
**.Params.categories** < br >
< br >
**All Params are only accessible using all lowercase characters**< br >
2013-08-17 12:34:25 +00:00
## Node Variables
In Hugo a node is any page not rendered directly by a content file. This
includes indexes, lists and the homepage.
**.Title** The title for the content.< br >
**.Date** The date the content is published on.< br >
**.Permalink** The Permanent link for this node< br >
**.Url** The relative url for this node.< br >
2014-11-25 08:07:18 +00:00
**.Ref(ref)** Returns the permalink for `ref` . See [cross-references ]({{% ref "extras/crossreferences.md" %}} ). Does not handle in-page fragments correctly.< br >
**.RelRef(ref)** Returns the relative permalink for `ref` . See [cross-references ]({{% ref "extras/crossreferences.md" %}} ). Does not handle in-page fragments correctly.< br >
2013-08-17 12:34:25 +00:00
**.RSSLink** Link to the indexes' rss link < br >
2014-01-22 01:05:26 +00:00
**.Data** The data specific to this type of node.< br >
2014-08-20 01:27:13 +00:00
**.IsNode** Always true for nodes.< br >
**.IsPage** Always false for nodes.< br >
2013-08-17 12:34:25 +00:00
**.Site** See site variables below< br >
## Site Variables
2013-07-04 15:32:55 +00:00
Also available is `.Site` which has the following:
2015-01-12 04:05:32 +00:00
**.Site.BaseUrl** The base URL for the site as defined in the site configuration file.< br >
2014-08-30 03:41:53 +00:00
**.Site.Taxonomies** The indexes for the entire site.< br >
2013-07-04 15:32:55 +00:00
**.Site.LastChange** The date of the last change of the most recent content.< br >
2013-11-18 23:31:02 +00:00
**.Site.Recent** Array of all content ordered by Date, newest first.< br >
2015-01-05 10:49:10 +00:00
**.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"
2015-01-12 04:05:32 +00:00
**.Site.Sections** Top level directories of the site.< br >
**.Site.Pages** All of the content pages of the site.< br >
**.Site.Files** All of the source files of the site.< br >
**.Site.Menus** All of the menus in the site.< br >
**.Site.Title** A string representing the title of the site.< br >
**.Site.Author** A map of the authors as defined in the site configuration.< br >
**.Site.LanguageCode** A string representing the language as defined in the site configuration.< br >
**.Site.DisqusShortname** A string representing the shortname of the Disqus shortcode as defined in the site configuration.< br >
**.Site.Copyright** A string representing the copyright of your web site as defined in the site configuration.< br >
**.Site.LastChange** A string representing the last time content has been updated.< br >
**.Site.Permalinks** A string to override the default permalink format. Defined in the site configuration.< br >
**.Site.BuildDrafts** A boolean (Default: false) to indicate whether to build drafts. Defined in the site configuration.< br >