HUGO

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
gohugoio Star
  • About Hugo
    • Overview
    • What is Hugo
    • Hugo features
    • Static site generators
    • Hugo's security model
    • Hugo and the GDPR
    • License
  • Installation
    • Overview
    • macOS
    • Linux
    • Windows
    • BSD
  • Getting started
    • Overview
    • Quick start
    • Basic usage
    • Directory structure
    • Configuration
    • Configure markup
    • Glossary of terms
    • External learning resources
  • Quick reference
    • Overview
    • Emojis
    • Functions
    • Methods
    • Page collections
  • 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
    • Markdown attributes
    • Syntax highlighting
    • Diagrams
    • Mathematics
  • Templates
    • Overview
    • Templating
    • Template lookup order
    • Base templates and blocks
    • Single page templates
    • List templates
    • Homepage template
    • Section templates
    • Taxonomy templates
    • Pagination
    • Content view templates
    • Partial templates
    • Shortcode templates
    • Menu templates
    • Data templates
    • RSS templates
    • Sitemap templates
    • Internal templates
    • Custom output formats
    • 404 page
    • Robots.txt
  • Functions
    • Overview
    • cast
    • collections
    • compare
    • crypto
    • data
    • debug
    • diagrams
    • encoding
    • fmt
    • global
    • go template
    • hugo
    • images
    • inflect
    • js
    • lang
    • math
    • openapi3
    • os
    • partials
    • path
    • reflect
    • resources
    • safe
    • strings
    • templates
    • time
    • transform
    • urls
  • Methods
    • Overview
    • Duration
    • Menu
    • Menu entry
    • Page
    • Pages
    • Resource
    • Shortcode
    • Site
    • Taxonomy
    • Time
  • Render hooks
    • Overview
    • Introduction
    • Code blocks
    • Headings
    • Images
    • Links
  • Hugo Modules
    • Overview
    • Configure Hugo modules
    • Use Hugo Modules
    • Theme components
  • Hugo Pipes
    • Overview
    • Introduction
    • Transpile Sass to CSS
    • PostCSS
    • PostProcess
    • JavaScript building
    • Babel
    • Asset minification
    • Concatenating assets
    • Fingerprinting and SRI hashing
    • Resource from string
    • Resource from template
  • CLI
  • Troubleshooting
    • Overview
    • Audit
    • Logging
    • Inspection
    • Deprecation
    • Performance
    • FAQs
  • Developer tools
    • Overview
    • Editor plugins
    • Front-ends
    • Search
    • Migrations
    • Other projects
  • Hosting and deployment
    • Overview
    • Hugo Deploy
    • Deploy with Rclone
    • Deploy with Rsync
    • Host on 21YunBox
    • Host on AWS Amplify
    • Host on Azure Static Web Apps
    • Host on Cloudflare Pages
    • Host on Firebase
    • Host on GitHub Pages
    • Host on GitLab Pages
    • Host on KeyCDN
    • Host on Netlify
    • Host on Render
  • Contribute
    • Overview
    • Development
    • Documentation
    • Themes
  • Maintenance
QUICK REFERENCE

Methods

A quick reference guide to Hugo’s methods, grouped by object.

Duration

Use these methods with time.Duration values.

Abs
Returns the absolute value of the given time.Duration value.
Hours
Returns the time.Duration value as a floating point number of hours.
Microseconds
Returns the time.Duration value as an integer microsecond count.
Milliseconds
Returns the time.Duration value as an integer millisecond count.
Minutes
Returns the time.Duration value as a floating point number of minutes.
Nanoseconds
Returns the time.Duration value as an integer nanosecond count.
Round
Returns the result of rounding DURATION1 to the nearest multiple of DURATION2.
Seconds
Returns the time.Duration value as a floating point number of seconds.
Truncate
Returns the result of rounding DURATION1 toward zero to a multiple of DURATION2.

Menu

Use these methods when ranging through menu entries.

ByName
Returns the given menu with its entries sorted by name.
ByWeight
Returns the given menu with its entries sorted by weight, then by name, then by identifier.
Limit
Returns the given menu, limited to the first N entries.
Reverse
Returns the given menu, reversing the sort order of its entries.

Menu entry

Use these methods in your menu templates.

Children
Returns a collection of child menu entries, if any, under the given menu entry.
HasChildren
Reports whether the given menu entry has child menu entries.
Identifier
Returns the identifier property of the given menu entry.
KeyName
Returns the identifier property of the given menu entry, falling back to its name property.
Menu
Returns the identifier of the menu that contains the given menu entry.
Name
Returns the name property of the given menu entry.
Page
Returns the Page object associated with the given menu entry.
Params
Returns the params property of the given menu entry.
Parent
Returns the parent property of the given menu entry.
Post
Returns the post property of the given menu entry.
Pre
Returns the pre property of the given menu entry.
Title
Returns the title property of the given menu entry.
URL
Returns the relative permalink of the page associated with the given menu entry, else its url property.
Weight
Returns the weight property of the given menu entry.

Page

Use these methods with a Page object.

Aliases
Returns the URL aliases as defined in front matter.
AllTranslations
Returns all translation of the given page, including the given page.
AlternativeOutputFormats
Returns a slice of OutputFormat objects, excluding the current output format, each representing one of the output formats enabled for the given page.
Ancestors
Returns a collection of Page objects, one for each ancestor section of the given page.
BundleType
Returns the bundle type of the given page, or an empty string if the page is not a page bundle.
CodeOwners
Returns of slice of code owners for the given page, derived from the CODEOWNERS file in the root of the project directory.
Content
Returns the rendered content of the given page.
CurrentSection
Returns the Page object of the section in which the given page resides.
Data
Returns a unique data object for each page kind.
Date
Returns the date of the given page.
Description
Returns the description of the given page as defined in front matter.
Draft
Reports whether the given page is a draft as defined in front matter.
Eq
Reports whether two Page objects are equal.
ExpiryDate
Returns the expiry date of the given page.
File
For pages backed by a file, returns file information for the given page.
FirstSection
Returns the Page object of the top level section of which the given page is a descendant.
Fragments
Returns a data structure of the fragments in the given page.
FuzzyWordCount
Returns the number of words in the content of the given page, rounded up to the nearest multiple of 100.
GetPage
Returns a Page object from the given path.
GetTerms
Returns a collection of term pages for terms defined on the given page in the given taxonomy, ordered according to the sequence in which they appear in front matter.
GitInfo
Returns Git information related to the last commit of the given page.
HasMenuCurrent
Reports whether the given page object matches the page object associated with one of the child menu entries under the given menu entry in the given menu.
HasShortcode
Reports whether the given shortcode is called by the given page.
HeadingsFiltered
Returns a slice of headings for each page related to the given page.
InSection
Reports whether the given page is in the given section.
IsAncestor
Reports whether PAGE1 in an ancestor of PAGE2.
IsDescendant
Reports whether PAGE1 in a descendant of PAGE2.
IsHome
Reports whether the given page is the home page.
IsMenuCurrent
Reports whether the given page object matches the page object associated with the given menu entry in the given menu.
IsNode
Reports whether the given page is a node.
IsPage
Reports whether the given page is a regular page.
IsSection
Reports whether the given page is a section page.
IsTranslated
Reports whether the given page has one or more translations.
Keywords
Returns a slice of keywords as defined in front matter.
Kind
Returns the kind of the given page.
Language
Returns the language object for the given page.
Lastmod
Returns the last modification date of the given page.
Layout
Returns the layout for the given page as defined in front matter.
Len
Returns the length, in bytes, of the rendered content of the given page.
LinkTitle
Returns the link title of the given page.
Next
Returns the next page in a global page collection, relative to the given page.
NextInSection
Returns the next page within a section, relative to the given page.
OutputFormats
Returns a slice of OutputFormat objects, each representing one of the output formats enabled for the given page.
Page
Returns the Page object of the given page.
Pages
Returns a collection of regular pages within the current section, and section pages of immediate descendant sections.
Paginate
Paginates a collection of pages.
Paginator
Paginates the collection of regular pages received in context.
Param
Returns a page parameter with the given key, falling back to a site parameter if present.
Params
Returns a map of custom parameters as defined in the front matter of the given page.
Parent
Returns the Page object of the parent section of the given page.
Path
Returns the logical path of the given page.
Permalink
Returns the permalink of the given page.
Plain
Returns the rendered content of the given page, removing all HTML tags.
PlainWords
Calls the Plain method, splits the result into a slice of words, and returns the slice.
Prev
Returns the previous page in a global page collection, relative to the given page.
PrevInSection
Returns the previous page within a section, relative to the given page.
PublishDate
Returns the publish date of the given page.
RawContent
Returns the raw content of the given page.
ReadingTime
Returns the estimated reading time, in minutes, for the given page.
Ref
Returns the absolute URL of the page with the given path, language, and output format.
RegularPages
Returns a collection of regular pages within the current section.
RegularPagesRecursive
Returns a collection of regular pages within the current section, and regular pages within all descendant sections.
RelPermalink
Returns the relative permalink of the given page.
RelRef
Returns the relative URL of the page with the given path, language, and output format.
Render
Renders the given template with the given page as context.
RenderShortcodes
Renders all shortcodes in the content of the given page, preserving the surrounding markup.
RenderString
Renders markup to HTML.
Resources
Returns a collection of page resources.
Scratch
Creates a "scratch pad" on the given page to store and manipulate data.
Section
Returns the name of the top level section in which the given page resides.
Sections
Returns a collection of section pages, one for each immediate descendant section of the given page.
Site
Returns the Site object.
Sitemap
Returns the sitemap settings for the given page as defined in front matter, falling back to the sitemap settings as defined in the site configuration.
Sites
Returns a collection of all Site objects, one for each language, ordered by language weight.
Slug
Returns the URL slug of the given page as defined in front matter.
Store
Creates a persistent "scratch pad" on the given page to store and manipulate data.
Summary
Returns the content summary of the given page.
TableOfContents
Returns a table of contents for the given page.
Title
Returns the title of the given page.
TranslationKey
Returns the translation key of the given page.
Translations
Returns all translation of the given page, excluding the current language.
Truncated
Reports whether the content length exceeds the summary length.
Type
Returns the content type of the given page.
Weight
Returns the weight of the given page as defined in front matter.
WordCount
Returns the number of words in the content of the given page.

Pages

Use these methods with a collection of Page objects.

ByDate
Returns the given page collection sorted by date in ascending order.
ByExpiryDate
Returns the given page collection sorted by expiration date in ascending order.
ByLanguage
Returns the given page collection sorted by language in ascending order.
ByLastmod
Returns the given page collection sorted by last modification date in ascending order.
ByLength
Returns the given page collection sorted by content length in ascending order.
ByLinkTitle
Returns the given page collection sorted by link title in ascending order, falling back to title if link title is not defined.
ByParam
Returns the given page collection sorted by the given parameter in ascending order.
ByPublishDate
Returns the given page collection sorted by publish date in ascending order.
ByTitle
Returns the given page collection sorted by title in ascending order.
ByWeight
Returns the given page collection sorted by weight in ascending order.
GroupBy
Returns the given page collection grouped by the given field in ascending order.
GroupByDate
Returns the given page collection grouped by date in descending order.
GroupByExpiryDate
Returns the given page collection grouped by expiration date in descending order.
GroupByLastmod
Returns the given page collection grouped by last modification date in descending order.
GroupByParam
Returns the given page collection grouped by the given parameter in ascending order.
GroupByParamDate
Returns the given page collection grouped by the given date parameter in descending order.
GroupByPublishDate
Returns the given page collection grouped by publish date in descending order.
Len
Returns the number of pages in the given page collection.
Limit
Returns the first N pages from the given page collection.
Next
Returns the next page in a local page collection, relative to the given page.
Prev
Returns the previous page in a local page collection, relative to the given page.
Related
Returns a collection of pages related to the given page.
Reverse
Returns the given page collection in reverse order.

Resource

Use these methods with global, page, and remote Resource objects.

Colors
Applicable to images, returns a slice of the most dominant colors using a simple histogram method.
Content
Returns the content of the given resource.
Crop
Applicable to images, returns an image resource cropped to the given dimensions without resizing.
Data
Applicable to resources returned by the resources.GetRemote function, returns information from the HTTP response.
Err
Applicable to resources returned by the resources.GetRemote function, returns an error message if the HTTP request fails, else nil.
Exif
Applicable to JPEG and TIFF images, returns an EXIF object containing image metadata.
Fill
Applicable to images, returns an image resource cropped and resized to the given dimensions.
Filter
Applicable to images, applies one or more image filters to the given image resource.
Fit
Applicable to images, returns an image resource downscaled to fit the given dimensions while maintaining aspect ratio.
Height
Applicable to images, returns the height of the given resource.
Key
Returns the unique key for the given resource, equivalent to its publishing path.
MediaType
Returns a media type object for the given resource.
Name
Returns the name of the given resource as optionally defined in front matter, falling back to a relative path or hashed file name depending on resource type.
Params
Returns a map of resource parameters as defined in front matter.
Permalink
Publishes the given resource and returns its permalink.
Process
Applicable to images, returns an image resource processed with the given specification.
Publish
Publishes the given resource.
RelPermalink
Publishes the given resource and returns its relative permalink.
Resize
Applicable to images, returns an image resource resized to the given width and/or height.
ResourceType
Returns the main type of the given resource's media type.
Title
Returns the title of the given resource as optionally defined in front matter, falling back to a relative path or hashed file name depending on resource type.
Width
Applicable to images, returns the width of the given resource.

Shortcode

Use these methods in your shortcode templates.

Get
Returns the value of the given parameter.
Inner
Returns the content between opening and closing shortcode tags, applicable when the shortcode call includes a closing tag.
InnerDeindent
Returns the content between opening and closing shortcode tags, with indentation removed, applicable when the shortcode call includes a closing tag.
IsNamedParams
Reports whether the shortcode call uses named parameters.
Name
Returns the shortcode file name, excluding the file extension.
Ordinal
Returns the zero-based ordinal of the shortcode in relation to its parent.
Page
Returns the Page object from which the shortcode was called.
Params
Returns a collection of the shortcode parameters.
Parent
Returns the parent shortcode context in nested shortcodes.
Position
Returns the filename and position from which the shortcode was called.
Ref
Returns the absolute URL of the page with the given path, language, and output format.
RelRef
Returns the relative URL of the page with the given path, language, and output format.
Scratch
Creates a "scratch pad" scoped to the shortcode to store and manipulate data.
Site
Returns the Site object.

Site

Use these methods with Site objects. A multilingual project will have two or more sites, one for each language.

AllPages
Returns a collection of all pages in all languages.
BaseURL
Returns the base URL as defined in the site configuration.
BuildDrafts
Reports whether the current build includes draft pages.
Config
Returns a subset of the site configuration.
Copyright
Returns the copyright notice as defined in the site configuration.
Data
Returns a data structure composed from the files in the data directory.
DisqusShortname
Returns the Disqus shortname as defined in the site configuration.
GetPage
Returns a Page object from the given path.
GoogleAnalytics
Returns the Google Analytics tracking ID as defined in the site configuration.
Home
Returns the home Page object for the given site.
IsDevelopment
Reports whether the current running environment is “development”.
IsMultiLingual
Reports whether the site is multilingual.
IsServer
Reports whether the built-in development server is running.
Language
Returns the language object for the given site.
LanguagePrefix
Returns the URL language prefix, if any, for the given site.
Languages
Returns a collection of language objects for all sites, ordered by language weight.
LastChange
Returns the last modification date of site content.
Lastmod
Returns the last modification date of site content.
MainSections
Returns a slice of the main section names as defined in the site configuration, falling back to the top level section with the most pages.
Menus
Returns a collection of menu objects for the given site.
Pages
Returns a collection of all pages.
Param
Returns the site parameter with the given key.
Params
Returns a map of custom parameters as defined in the site configuration.
RegularPages
Returns a collection of all regular pages.
Sections
Returns a collection of first level section pages.
Sites
Returns a collection of all Site objects, one for each language, ordered by default content language then by language weight.
Taxonomies
Returns a data structure containing the site's taxonomy objects, the terms within each taxonomy object, and the pages to which the terms are assigned.
Title
Returns the title as defined in the site configuration.

Taxonomy

Use these methods with Taxonomy objects.

Alphabetical
Returns an ordered taxonomy, sorted alphabetically by term.
ByCount
Returns an ordered taxonomy, sorted by the number of pages associated with each term.
Count
Returns the number of number of weighted pages to which the given term has been assigned.
Get
Returns a slice of weighted pages to which the given term has been assigned.

Time

Use these methods with time.Time values.

Add
Returns the given time plus the given duration.
AddDate
Returns the time corresponding to adding the given number of years, months, and days to the given time.Time value.
After
Reports whether TIME1 is after TIME2.
Before
Reports whether TIME1 is before TIME2.
Day
Returns the day of the month of the given time.Time value.
Equal
Reports whether TIME1 is equal to TIME2.
Format
Returns a textual representation of the time.Time value formatted according to the layout string.
Hour
Returns the hour within the day of the given time.Time value, in the range [0, 23].
IsDST
Reports whether the given time.Time value is in Daylight Savings Time.
IsZero
Reports whether the given time.Time value represents the zero time instant, January 1, year 1, 00:00:00 UTC.
Local
Returns the given time.Time value with the location set to local time.
Minute
Returns the minute offset within the hour of the given time.Time value, in the range [0, 59].
Month
Returns the month of the year of the given time.Time value.
Nanosecond
Returns the nanosecond offset within the second of the given time.Time value, in the range [0, 999999999].
Second
Returns the second offset within the minute of the given time.Time value, in the range [0, 59].
Sub
Returns the duration computed by subtracting TIME2 from TIME1.
Unix
Returns the given time.Time value expressed as the number of seconds elapsed since January 1, 1970 UTC.
UnixMicro
Returns the given time.Time value expressed as the number of microseconds elapsed since January 1, 1970 UTC.
UnixMilli
Returns the given time.Time value expressed as the number of milliseconds elapsed since January 1, 1970 UTC.
UnixNano
Returns the given time.Time value expressed as the number of nanoseconds elapsed since January 1, 1970 UTC.
UTC
Returns the given time.Time value with the location set to UTC.
Weekday
Returns the day of the week of the given time.Time value.
Year
Returns the year of the given time.Time value.
YearDay
Returns the day of the year of the given time.Time value, in the range [1, 365] for non-leap years, and [1,366] in leap years.

See also

  • Glossary of terms
  • Page collections
  • Code block render hooks
  • Emojis
  • Functions

On this page

  • Duration
  • Menu
  • Menu entry
  • Page
  • Pages
  • Resource
  • Shortcode
  • Site
  • Taxonomy
  • Time
Last updated: November 20, 2023: Adjust quick reference weights (5e432e12)
Improve this page
By the Hugo Authors
Hugo Logo
  • File an Issue
  • Get Help
  • @GoHugoIO
  • @spf13
  • @bepsays

Netlify badge

 

Hugo Sponsors

 

The Hugo logos are copyright © Steve Francia 2013–2024.

The Hugo Gopher is based on an original work by Renée French.

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
  • About Hugo
  • Installation
  • Getting started
  • Quick reference
  • Content management
  • Templates
  • Functions
  • Methods
  • Render hooks
  • Hugo Modules
  • Hugo Pipes
  • CLI
  • Troubleshooting
  • Developer tools
  • Hosting and deployment
  • Contribute
  • Maintenance