7.0 KiB
| title | linktitle | description | date | publishdate | lastmod | categories | tags | draft | weight | aliases | toc | needsreview | notesforauthors | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Page Variables | 2017-02-01 | 2017-02-01 | 2017-02-01 |
|
|
false | 20 | false | true |
The following is a list of page-level variables that can be defined for a piece of content. Many of these will be defined in the front matter, derived from file location, or extracted from the content itself.
{{% note ".Scratch" %}}
See .Scratch for page-scoped writable variables.
{{% /note %}}
.ContentThe content itself, defined below the front matter..DataThe data specific to this type of page..DateThe date the page is associated with..DescriptionThe description for the page..DraftA boolean,trueif the content is marked as a draft in the front matter..ExpiryDateThe date where the content is scheduled to expire on..FuzzyWordCountThe approximate number of words in the content..HugoSee Hugo Variables.IsHomeTrue if this is the home page..IsNodeAlways false for regular content pages..IsPageAlways true for regular content pages..IsTranslatedWhether there are any translations to display..KeywordsThe meta keywords for this content..KindWhat kind of page is this: is one of page, home, section, taxonomy or taxonomyTerm. There are also RSS, sitemap, robotsTXT and 404, but these will only available during rendering of that kind of page, and not available in any of thePagescollections..LangLanguage taken from the language extension notation..LanguageA language object that points to this the language's definition in the site config..LastmodThe date the content was last modified..LinkTitleAccess when creating links to this content. Will uselinktitleif set in front matter, elsetitle..NextPointer to the following content (based on pub date)..NextInSectionPointer to the following content within the same section (based on pub date).Pagesa collection of associated pages. This will be nil for regular content pages. This is an alias for.Data.Pages..PermalinkThe Permanent link for this page..PrevPointer to the previous content (based on pub date)..PrevInSectionPointer to the previous content within the same section (based on.PublishDate). For example,{{if .PrevInSection}}{{.PrevInSection.Permalink}}{{end}}..PublishDateThe date the content is published on..RSSLinkLink to the taxonomies' RSS link..RawContentRaw markdown content without the front matter. Useful with remarkjs.com.ReadingTimeThe estimated time it takes to read the content in minutes..RefReturns the permalink for a given reference;e.g.,.Ref "sample.md". See Cross References. Does not handle in-page fragments correctly..RelPermalinkThe Relative permanent link for this page..RelRefReturns the relative permalink for a given reference. Example:RelRef "sample.md". See Cross References. This does not handle in-page fragments..SectionThe section this content belongs to..SiteSee Site Variables below..SummaryA 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..TableOfContentsThe rendered table of contents for the page..TitleThe title for this page..TranslationsA list of translated versions of the current page. See Multilingual for more info..TruncatedA boolean,trueif the.Summaryis truncated. Useful for showing a "Read more..." link only if necessary. See Summaries for more details..TypeThe content type (e.g.,post)..URLThe relative URL for this page. Note that ifURLis set directly in front matter, that URL is returned as-is..UniqueIDThe MD5-checksum of the content file's path.WeightAssigned weight (in the front matter) to this content, used in sorting..WordCountThe number of words in the content.
Page-level Params
Any other value defined in the front matter, including taxonomies, will be made available as part of the `.Params variable.
For example, the tags and categories taxonomies are accessed with:
.Params.tags.Params.categories
{{% note "Casing of Params" %}}
Page-level .Params are only accessible in lowercase.
{{% /note %}}
This is particularly useful for the introduction of user-defined fields in content files. For example, a Hugo website on book reviews could have the following front matter in /content/review/book01.md:
---
...
affiliatelink: "http://www.my-book-link.here"
recommendedby: "My Mother"
---
Which would then be accessible to a template at /themes/yourtheme/layouts/review/single.html through .Params.affiliatelink and .Params.recommendedby, respectively. Two common situations where these could be introduced are as a value of a certain attribute (like href="" below) or by itself to be displayed. Sample syntaxes include:
<h3><a href={{ printf "%s" $.Params.affiliatelink }}>Buy this book</a></h3>
<p>It was recommended by {{ .Params.recommendedby }}.</p>
which would render
<h3><a href="http://www.my-book-link.here">Buy this book</a></h3>
<p>It was recommended by my Mother.</p>
{{% note %}}
See Archetypes for consistency of Params across pieces of content.
{{% /note %}}
Param method
In Hugo, you can declare params both for the site and the individual page. A common use case is to have a general value for the site and a more specific value for some of the pages (i.e., a header image):
{{ $.Param "header_image" }}
The .Param method provides a way to resolve a single value whether it's
in a page parameter or a site parameter.
When front matter contains nested fields like the following:
---
author:
given_name: John
family_name: Feminella
display_name: John Feminella
---
.Param can access them by concatenating the field names together with a
dot:
{{ $.Param "author.display_name" }}
If your front matter contains a top-level key that is ambiguous with a nested key, as in the following case:
---
favorites.flavor: vanilla
favorites:
flavor: chocolate
---
The top-level key will be preferred. Therefore, the following method, when applied to the previous example, will print vanilla and not chocolate:
{{ $.Param "favorites.flavor" }}