Functions
cast
Use these functions to cast a value from one data type to another.
cast.ToFloatReturns the given value converted to a decimal floating-point number (base 10).
cast.ToIntReturns the given value converted to a decimal integer (base 10).
cast.ToStringReturns the given value converted to a string.
collections
Use these functions to manipulate and query maps, slices, and strings.
collections.AfterReturns a slice containing the elements after the first N elements of the given slice.
collections.AppendReturns a slice by adding one or more elements, or an entire second slice, to the end of the given slice.
collections.ApplyReturns a slice by transforming each element of the given slice using a specific function and parameters.
collections.ComplementReturns a slice by identifying elements in the last given slice that do not appear in any of the preceding slices.
collections.DReturns a sorted slice of unique random integers based on a given seed, count, and maximum value.
collections.DelimitReturns a string by joining the values of the given slice or map with a delimiter.
collections.DictionaryReturns a map created from the given key-value pairs.
collections.FirstReturns the first N elements of the given slice or string.
collections.GroupReturns a map by grouping the given page collection (slice) by a specific key.
collections.InReports whether a value exists within the given slice or string.
collections.IndexReturns an element or value from the given slice or map at the specified key(s).
collections.IntersectReturns a slice containing the common elements found in two given slices, in the same order as the first slice.
collections.IsSetReports whether a specific key or index exists in the given map or slice.
collections.KeyValsReturns a KeyVals struct by pairing a given key and values.
collections.LastReturns the last N elements of the given slice or string.
collections.MergeReturns a map by combining two or more given maps.
collections.NewScratchReturns a locally scoped persistent data structure for storing and manipulating keyed values.
collections.QuerifyReturns a URL query string from the given map, slice, or sequence of key-value pairs.
collections.ReverseReturns a slice by reversing the order of elements in the given slice.
collections.SeqReturns a slice of integers starting from 1 or a given value, incrementing by 1 or a given value, and ending at a given value.
collections.ShuffleReturns a slice by randomizing the element order of the given slice.
collections.SliceReturns a slice created from the given values.
collections.SortReturns a sorted map or slice by reordering the given collection by a key and order.
collections.SymDiffReturns a slice containing the symmetric difference of two given slices.
collections.UnionReturns a slice containing the unique elements from two given slices.
collections.UniqReturns a slice by removing duplicate elements from the given slice.
collections.WhereReturns a slice by filtering the given slice based on a key, operator, and value.
compare
Use these functions to compare two or more values.
compare.ConditionalReturns one of two arguments depending on the value of the control argument.
compare.DefaultReturns the second argument if set, else the first argument.
compare.EqReturns the boolean truth of arg1 == arg2 || arg1 == arg3.
compare.GeReturns the boolean truth of arg1 >= arg2 && arg1 >= arg3.
compare.GtReturns the boolean truth of arg1 > arg2 && arg1 > arg3.
compare.LeReturns the boolean truth of arg1 <= arg2 && arg1 <= arg3.
compare.LtReturns the boolean truth of arg1 < arg2 && arg1 < arg3.
compare.NeReturns the boolean truth of arg1 != arg2 && arg1 != arg3.
crypto
Use these functions to create cryptographic hashes.
crypto.HashReturns the checksum of the given input, encoded to a hexadecimal string, using the given hash algorithm.
crypto.HMACReturns a cryptographic hash that uses a key to sign a message.
crypto.MD5Returns the MD5 checksum of the given input, encoded to a hexadecimal string.
crypto.SHA1Returns the SHA1 checksum of the given input, encoded to a hexadecimal string.
crypto.SHA256Returns the SHA256 checksum of the given input, encoded to a hexadecimal string.
css
Use these functions to work with CSS and Sass files.
css.BuildReturns a resource created by bundling, transforming, and minifying the given CSS resource.
css.ChromaStylesReturns a CSS stylesheet for the syntax highlighter.
css.PostCSSReturns a resource created by processing the given CSS resource with PostCSS.
css.QuotedReturns the given string, setting its data type to indicate that it must be quoted when used in CSS.
css.SassReturns a resource created by transpiling the given Sass resource to CSS.
css.TailwindCSSReturns a resource created by processing the given resource with the Tailwind CSS CLI.
css.UnquotedReturns the given string, setting its data type to indicate that it must not be quoted when used in CSS.
debug
Use these functions to debug your templates.
debug.DumpReturns an object dump as a string.
debug.TimerReturns a named timer used to measure and report elapsed execution time to the console.
debug.VisualizeSpacesReturns the given string with spaces replaced by a visible string.
diagrams
Use these functions to render diagrams.
diagrams.GoatReturns an SVGDiagram object created from the given GoAT markup and options.
encoding
Use these functions to encode and decode data.
encoding.Base64DecodeReturns the base64 decoding of the given content.
encoding.Base64EncodeReturns the base64 decoding of the given content.
encoding.HexDecodeReturns the hexadecimal decoding of the given content.
encoding.HexEncodeReturns the hexadecimal encoding of the given content.
encoding.JsonifyReturns the given object encoded to JSON.
fmt
Use these functions to print strings within a template or to print messages to the terminal.
fmt.ErrorfLogs an ERROR from a template.
fmt.ErroridfLogs a suppressible ERROR from a template.
fmt.PrintReturns the default string representation of the given arguments.
fmt.PrintfReturns a string formatted according to the given format specifier.
fmt.PrintlnReturns the default string representation of the given arguments, followed by a line break.
fmt.WarnfLogs a WARNING from a template.
fmt.WarnidfLogs a suppressible WARNING from a template.
global
Use these global functions to access page and site data.
pageReturns the Page object of the current page, accessible from any context.
siteReturns the Site object of the current site, accessible from any context.
go template
Use these functions and statements to write conditionals, loops, and other template logic.
andReturns the first falsy argument. If all arguments are truthy, returns the last argument.
blockDefines a template and executes it in place.
breakStops the innermost range iteration and bypasses any remaining iterations.
continueStops the innermost range iteration and continues with the next iteration.
defineDefines a template.
elseBegins an alternate block for if, with, and range statements.
endTerminates if, with, range, block, and define statements.
ifExecutes the block if the expression is truthy.
lenReturns the length of a string, slice, map, or collection.
notReturns the boolean negation of its single argument.
orReturns the first truthy argument. If all arguments are falsy, returns the last argument.
rangeIterates over a non-empty collection, binds context (the dot) to successive elements, and executes the block.
returnTerminates execution of the current template and, when used within a partial template, returns the given value, if any.
templateExecutes the given template, optionally passing context.
tryReturns a TryValue object after evaluating the given expression.
urlqueryReturns the escaped value of the textual representation of its arguments in a form suitable for embedding in a URL query.
withBinds context (the dot) to the expression and executes the block if expression is truthy.
hash
Use these functions to create non-cryptographic hashes.
hash.FNV32aReturns the 32-bit FNV (Fowler-Noll-Vo) non-cryptographic hash of the given string.
hash.XxHashReturns the 64-bit xxHash non-cryptographic hash of the given string.
hugo
Use these functions to access information about the Hugo application and the current environment.
hugo.BuildDateReturns the compile date of the Hugo binary.
hugo.CommitHashReturns the Git commit hash of the Hugo binary.
hugo.DataReturns a data structure composed from the files in the data directory.
hugo.DepsReturns a slice of project dependencies, either modules or local theme components.
hugo.EnvironmentReturns the current running environment.
hugo.GeneratorReturns an HTML meta element identifying the software that generated the site.
hugo.GoVersionReturns the Go version used to compile the Hugo binary.
hugo.IsDevelopmentReports whether the current running environment is "development".
hugo.IsExtendedReports whether the Hugo binary is either the extended or extended/deploy edition.
hugo.IsMultihostReports whether each configured language has a unique base URL.
hugo.IsMultilingualReports whether there are two or more configured languages.
hugo.IsProductionReports whether the current running environment is "production".
hugo.IsServerReports whether the built-in development server is running.
hugo.SitesReturns a collection of all sites for all dimensions.
hugo.StoreReturns a globally scoped persistent data structure for storing and manipulating keyed values.
hugo.VersionReturns the current version of the Hugo binary.
hugo.WorkingDirReturns the project working directory.
images
Use these functions to create an image filter, apply an image filter to an image, and to retrieve image information.
images.AutoOrientReturns an image filter that rotates and flips an image as needed per its Exif orientation tag.
images.BrightnessReturns an image filter that changes the brightness of an image.
images.ColorBalanceReturns an image filter that changes the color balance of an image.
images.ColorizeReturns an image filter that produces a colorized version of an image.
images.ConfigReturns an image.Config structure from the image at the specified path, relative to the working directory.
images.ContrastReturns an image filter that changes the contrast of an image.
images.DitherReturns an image filter that dithers an image.
images.FilterReturns a new image resource created by applying one or more image filters to the given image resource.
images.GammaReturns an image filter that performs gamma correction on an image.
images.GaussianBlurReturns an image filter that applies a gaussian blur to an image.
images.GrayscaleReturns an image filter that produces a grayscale version of an image.
images.HueReturns an image filter that rotates the hue of an image.
images.InvertReturns an image filter that negates the colors of an image.
images.MaskReturns an image filter that applies a mask to the source image.
images.OpacityReturns an image filter that changes the opacity of an image.
images.OverlayReturns an image filter that overlays the source image at the given coordinates, relative to the upper left corner.
images.PaddingReturns an image filter that resizes the image canvas without resizing the image.
images.PixelateReturns an image filter that applies a pixelation effect to an image.
images.ProcessReturns an image filter that processes an image according to the given processing specification.
images.QRReturns an image resource containing a QR code encoded from the given text using the specified options.
images.SaturationReturns an image filter that changes the saturation of an image.
images.SepiaReturns an image filter that produces a sepia-toned version of an image.
images.SigmoidReturns an image filter that changes the contrast of an image using a sigmoidal function.
images.TextReturns an image filter that adds text to an image.
images.UnsharpMaskReturns an image filter that sharpens an image.
inflect
Use these functions for word inflection, such as singularization and pluralization of English nouns.
inflect.HumanizeReturns the humanized version of the input with the first letter capitalized.
inflect.PluralizeReturns the plural form of the given word according to a set of common English pluralization rules.
inflect.SingularizeReturns the singular form of the given word according to a set of common English singularization rules.
js
Use these functions to work with JavaScript and TypeScript files.
js.BabelReturns a resource created by transpiling the given JavaScript resource using Babel.
js.BatchReturns a batcher used to build JavaScript bundle groups with global code splitting and flexible hooks/runners setup.
js.BuildReturns a resource created by bundling, transpiling, tree shaking, and minifying the given JavaScript resource.
lang
Use these functions to adapt your site to meet language and regional requirements.
lang.FormatAccountingReturns a currency representation of a number for the given currency and precision for the current language and region in accounting notation.
lang.FormatCurrencyReturns a currency representation of a number for the given currency and precision for the current language and region.
lang.FormatNumberReturns a numeric representation of a number with the given precision for the current language and region.
lang.FormatNumberCustomReturns a numeric representation of a number with the given precision using negative, decimal, and grouping options.
lang.FormatPercentReturns a percentage representation of a number with the given precision for the current language and region.
lang.MergeReturns a copy of the given page collection with missing translations filled in from another page collection.
lang.TranslateReturns a translated string using the translation tables in the i18n directory.
math
Use these functions to perform mathematical operations.
math.AbsReturns the absolute value of the given number.
math.AcosReturns the arccosine, in radians, of the given number.
math.AddReturns the result of adding one or more numbers to the first number.
math.AsinReturns the arcsine, in radians, of the given number.
math.AtanReturns the arctangent, in radians, of the given number.
math.Atan2Returns the arctangent, in radians, of the given number pair, determining the correct quadrant from their signs.
math.CeilReturns the least integer value greater than or equal to the given number.
math.CosReturns the cosine of the given radian number.
math.CounterReturns a global counter value, incrementing it each time the function is called.
math.DivReturns the result of dividing the first number by one or more numbers.
math.FloorReturns the greatest integer value less than or equal to the given number.
math.LogReturns the natural logarithm of the given number.
math.MaxReturns the greater of all numbers. Accepts scalars, slices, or both.
math.MaxInt64Returns the maximum value for a signed 64-bit integer.
math.MinReturns the smaller of all numbers. Accepts scalars, slices, or both.
math.ModReturns the modulus of two integers.
math.ModBoolReports whether the modulus of two integers equals 0.
math.MulReturns the result of multiplying the first number by one or more numbers.
math.PiReturns the mathematical constant pi.
math.PowReturns the first number raised to the power of the second number.
math.ProductReturns the product of all numbers. Accepts scalars, slices, or both.
math.RandReturns a pseudo-random number in the half-open interval [0.0, 1.0).
math.RoundReturns the nearest integer, rounding half away from zero.
math.SinReturns the sine of the given radian number.
math.SqrtReturns the square root of the given number.
math.SubReturns the result of subtracting one or more numbers from the first number.
math.SumReturns the sum of all numbers. Accepts scalars, slices, or both.
math.TanReturns the tangent of the given radian number.
math.ToDegreesReturns the given radian value converted to degrees.
math.ToRadiansReturns the given degree value converted to radians.
openapi3
Use these functions to work with OpenAPI 3 definitions.
openapi3.UnmarshalReturns an OpenAPI 3 Description unmarshaled from the given resource.
os
Use these functions to interact with the operating system.
os.FileExistsReports whether the file or directory exists.
os.GetenvReturns the value of an environment variable, or an empty string if the environment variable is not set.
os.ReadDirReturns an array of FileInfo structures sorted by file name, one element for each directory entry.
os.ReadFileReturns the contents of a file.
os.StatReturns a FileInfo structure describing a file or directory.
partials
Use these functions to call partial templates.
partials.IncludeExecutes the given template, optionally passing context. If the partial template contains a return statement, returns the given value, else returns the rendered output.
partials.IncludeCachedExecutes the given template and caches the result, optionally passing one or more variant keys. If the partial template contains a return statement, returns the given value, else returns the rendered output.
path
Use these functions to work with file paths.
path.BaseReturns the last element of the given path, after replacing path separators with slashes (
/).path.BaseNameReturns the last element of the given path with its extension removed, if present, after replacing path separators with slashes (
/).path.CleanReturns the shortest path name equivalent to the given path, after replacing path separators with slashes (
/).path.DirReturns all but the last element of the given path, after replacing path separators with slashes (
/).path.ExtReturns the file extension of the given path, after replacing path separators with slashes (
/).path.JoinReturns the shortest path name equivalent to the given path elements joined into a single path, after replacing path separators with slashes (
/).path.SplitReturns the directory and file name components of the given path, split immediately following the final slash, after replacing path separators with slashes (
/).
reflect
Use these functions to determine a value's data type.
reflect.IsImageResourceReports whether the given value is a Resource object representing an image as defined by its media type.
reflect.IsImageResourceProcessableReports whether the given value is a Resource object representing an image from which Hugo can extract dimensions and perform processing such as converting, resizing, cropping, or filtering.
reflect.IsImageResourceWithMetaReports whether the given value is a Resource object representing an image from which Hugo can extract dimensions and, if present, Exif, IPTC, and XMP data.
reflect.IsMapReports whether the given value is a map.
reflect.IsPageReports whether the given value is a Page object.
reflect.IsResourceReports whether the given value is a Resource object.
reflect.IsSiteReports whether the given value is a Site object.
reflect.IsSliceReports whether the given value is a slice.
resources
Use these functions to work with resources.
resources.ByTypeReturns a collection of global resources of the given media type, or nil if none found.
resources.ConcatReturns a concatenated slice of resources.
resources.CopyReturns a copy of the given resource at the target path.
resources.ExecuteAsTemplateReturns a resource created from a Go template, parsed and executed with the given context.
resources.FingerprintReturns a fingerprinted resource, created by cryptographically hashing the content of the given resource.
resources.FromStringReturns a resource created from a string.
resources.GetReturns a global resource from the given path, or nil if none found.
resources.GetMatchReturns the first global resource from paths matching the given glob pattern, or nil if none found.
resources.GetRemoteReturns a remote resource from the given URL, or nil if none found.
resources.MatchReturns a collection of global resources from paths matching the given glob pattern, or nil if none found.
resources.MinifyReturns a minified version of the given resource.
resources.PostProcessReturns a resource that is processed after the build.
resources.PublishReturns the given resource after publishing it.
safe
Use these functions to declare a value as safe in the context of Go's html/template package.
safe.CSSReturns the given string declared as safe CSS.
safe.HTMLReturns the given string declared as safe HTML.
safe.HTMLAttrReturns the given key-value pair declared as a safe HTML attribute.
safe.JSReturns the given string declared as a safe JavaScript expression.
safe.JSStrReturns the given string declared as a safe JavaScript string.
safe.URLReturns the given string declared as a safe URL or URL substring.
strings
Use these functions to work with strings.
strings.ChompReturns the given string, removing all trailing newline characters and carriage returns.
strings.ContainsReports whether the given string contains the given substring.
strings.ContainsAnyReports whether the given string contains any character within the given set.
strings.ContainsNonSpaceReports whether the given string contains any non-space characters as defined by Unicode.
strings.CountReturns the number of non-overlapping instances of the given substring within the given string.
strings.CountRunesReturns the number of runes in the given string excluding whitespace.
strings.CountWordsReturns the number of words in the given string.
strings.DiffReturns an anchored diff of the two texts OLD and NEW in the unified diff format. If OLD and NEW are identical, returns an empty string.
strings.FindREReturns a slice of strings that match the regular expression.
strings.FindRESubmatchReturns a slice of all successive matches of the regular expression. Each element is a slice of strings holding the text of the leftmost match of the regular expression and the matches, if any, of its subexpressions.
strings.FirstUpperReturns the given string, converting the first character to uppercase.
strings.HasPrefixReports whether the given string begins with the given prefix.
strings.HasSuffixReports whether the given string ends with the given suffix.
strings.RepeatReturns the given string repeated the given number of times.
strings.ReplaceReturns the given string, replacing all occurrences of OLD with NEW.
strings.ReplacePairsReturns the given string, with multiple replacements performed in a single pass using a slice of old and new string pairs.
strings.ReplaceREReturns the given string, replacing all occurrences of a regular expression with a replacement pattern.
strings.RuneCountReturns the number of runes in the given string.
strings.SliceStringReturns a substring of the given string, beginning with the start position and ending before the end position.
strings.SplitReturns a slice of strings by splitting the given string by a delimiter.
strings.SubstrReturns a substring of the given string, beginning with the start position and ending after the given length.
strings.TitleReturns the given string, converting it to title case.
strings.ToLowerReturns the given string, converting all characters to lowercase.
strings.ToUpperReturns the given string, converting all characters to uppercase.
strings.TrimReturns the given string, removing leading and trailing characters specified in the cutset.
strings.TrimLeftReturns the given string, removing leading characters specified in the cutset.
strings.TrimPrefixReturns the given string, removing the prefix from the beginning of the string.
strings.TrimRightReturns the given string, removing trailing characters specified in the cutset.
strings.TrimSpaceReturns the given string, removing leading and trailing whitespace as defined by Unicode.
strings.TrimSuffixReturns the given string, removing the suffix from the end of the string.
strings.TruncateReturns the given string, truncating it to a maximum length without cutting words or leaving unclosed HTML tags.
templates
Use these functions to query the template system.
templates.CurrentReturns information about the currently executing template.
templates.DeferDefers execution of a template until all sites and output formats have been rendered.
templates.ExistsReports whether a template file exists under the given path relative to the layouts directory.
templates.InnerExecutes the content block enclosed by a partial call.
time
Use these functions to work with time values.
time.AsTimeReturns the given string representation of a date/time value as a time.Time value.
time.DurationReturns a time.Duration value using the given time unit and number.
time.FormatReturns the given date/time as a formatted and localized string.
time.InReturns the given date/time as represented in the specified IANA time zone.
time.NowReturns the current local time.
time.ParseDurationReturns a time.Duration value by parsing the given duration string.
transform
Use these functions to transform values from one format to another.
transform.CanHighlightReports whether the given language is supported for syntax highlighting.
transform.EmojifyReturns the given string with emoji shortcodes replaced by their corresponding emoji characters.
transform.HighlightReturns the given code rendered with a syntax highlighter.
transform.HighlightCodeBlockReturns highlighted code received in context within a code block render hook.
transform.HTMLEscapeReturns the given string, escaping special characters by replacing them with HTML entities.
transform.HTMLToMarkdownReturns the given HTML converted to Markdown.
transform.HTMLUnescapeReturns the given string, replacing each HTML entity with its corresponding character.
transform.MarkdownifyReturns the given Markdown rendered to HTML.
transform.PlainifyReturns a string with all HTML tags removed.
transform.PortableTextReturns the given Portable Text converted to Markdown.
transform.RemarshalReturns a string of serialized data in the specified format, marshaled from a string of serialized data or a map.
transform.ToMathReturns the given mathematical markup, written in the LaTeX language, rendered to HTML.
transform.UnmarshalReturns a map or an array parsed from serialized data in CSV, JSON, TOML, YAML, or XML format.
transform.XMLEscapeReturns the given string, removing disallowed characters then escaping the result to its XML equivalent.
urls
Use these functions to work with URLs.
urls.AbsLangURLReturns an absolute URL with a language prefix, if any.
urls.AbsURLReturns an absolute URL.
urls.AnchorizeReturns the given string, sanitized for usage in an HTML id attribute.
urls.JoinPathReturns a URL string created by joining the provided elements and cleaning the result of any ./ or ../ elements, or an empty string if the argument list is empty.
urls.ParseReturns a URL structure parsed from the given URL.
urls.PathEscapeReturns the given string, applying percent-encoding to special characters and reserved delimiters so it can be safely used as a segment within a URL path.
urls.PathUnescapeReturns the given string, replacing all percent-encoded sequences with the corresponding unescaped characters.
urls.RefReturns the absolute URL of the page with the given path, language, and output format.
urls.RelLangURLReturns a relative URL with a language prefix, if any.
urls.RelRefReturns the relative URL of the page with the given path, language, and output format.
urls.RelURLReturns a relative URL.
urls.URLizeReturns the given string, sanitized for usage in a URL.
