Functions
cast
Use these functions to cast a value from one data type to another.
cast.ToFloatConverts a value to a decimal floating-point number (base 10).
cast.ToIntConverts a value to a decimal integer (base 10).
cast.ToStringConverts a value 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.HMACReturns a cryptographic hash that uses a key to sign a message.
crypto.MD5Hashes the given input and returns its MD5 checksum encoded to a hexadecimal string.
crypto.SHA1Hashes the given input and returns its SHA1 checksum encoded to a hexadecimal string.
crypto.SHA256Hashes the given input and returns its SHA256 checksum encoded to a hexadecimal string.
css
Use these functions to work with CSS and Sass files.
css.BuildBundle, transform, and minify CSS resources.
css.PostCSSProcesses the given resource with PostCSS using any PostCSS plugin.
css.QuotedReturns the given string, setting its data type to indicate that it must be quoted when used in CSS.
css.SassTranspiles Sass to CSS.
css.TailwindCSSProcesses 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.TimerCreates a named timer that reports elapsed 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.JsonifyEncodes the given object to JSON.
fmt
Use these functions to print strings within a template or to print messages to the terminal.
fmt.ErrorfLog an ERROR from a template.
fmt.ErroridfLog a suppressible ERROR from a template.
fmt.PrintPrints the default representation of the given arguments using the standard
fmt.Printfunction.fmt.PrintfFormats a string using the standard
fmt.Sprintffunction.fmt.PrintlnPrints the default representation of the given argument using the standard
fmt.Printfunction and enforces a line break.fmt.WarnfLog a WARNING from a template.
fmt.WarnidfLog a suppressible WARNING from a template.
global
Use these global functions to access page and site data.
go template
These are the functions, operators, and statements provided by Go's text/template package.
andReturns the first falsy argument. If all arguments are truthy, returns the last argument.
blockDefines a template and executes it in place.
breakUsed with the range statement, stops the innermost iteration and bypasses all remaining iterations.
continueUsed with the range statement, stops the innermost iteration and continues to 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.
returnUsed within partial templates, terminates template execution and 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 Hugo Modules or local theme components.
hugo.EnvironmentReturns the current running environment.
hugo.GeneratorRenders 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.FilterApplies 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.QREncodes the given text into a QR code using the specified options, returning an image resource.
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
These functions provide word inflection features such as singularization and pluralization of English nouns.
inflect.HumanizeReturns the humanized version of the input with the first letter capitalized.
inflect.PluralizePluralizes the given word according to a set of common English pluralization rules.
inflect.SingularizeSingularizes the given word according to a set of common English singularization rules.
js
Use these functions to work with JavaScript and TypeScript files.
js.BabelCompile the given JavaScript resource with Babel.
js.BatchBuild JavaScript bundle groups with global code splitting and flexible hooks/runners setup.
js.BuildBundle, transpile, tree shake, and minify JavaScript resources.
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.MergeMerge missing translations from other languages.
lang.TranslateTranslates a 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.AddAdds two or more numbers.
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.CounterIncrements and returns a global counter.
math.DivDivides 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.MulMultiplies two 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.SubSubtracts 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.ToDegreesToDegrees converts radians into degrees.
math.ToRadiansToRadians converts degrees into radians.
openapi3
Use these functions to work with OpenAPI 3 definitions.
openapi3.UnmarshalUnmarshals the given resource into an OpenAPI 3 Description.
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.BaseReplaces path separators with slashes (
/) and returns the last element of the given path.path.BaseNameReplaces path separators with slashes (
/) and returns the last element of the given path, removing the extension if present.path.CleanReplaces path separators with slashes (
/) and returns the shortest path name equivalent to the given path.path.DirReplaces path separators with slashes (/) and returns all but the last element of the given path.
path.ExtReplaces path separators with slashes (
/) and returns the file name extension of the given path.path.JoinReplaces path separators with slashes (
/), joins the given path elements into a single path, and returns the shortest path name equivalent to the result.path.SplitReplaces path separators with slashes (
/) and splits the resulting path immediately following the final slash, separating it into a directory and file name component.
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.CopyCopies the given resource to the target path.
resources.ExecuteAsTemplateReturns a resource created from a Go template, parsed and executed with the given context.
resources.FingerprintCryptographically hashes 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.MinifyMinifies the given resource.
resources.PostProcessProcesses the given resource after the build.
safe
Use these functions to declare a value as safe in the context of Go's html/template package.
safe.CSSDeclares the given string as a safe CSS string.
safe.HTMLDeclares the given string as a safeHTML string.
safe.HTMLAttrDeclares the given key-value pair as a safe HTML attribute.
safe.JSDeclares the given string as a safe JavaScript expression.
safe.JSStrDeclares the given string as a safe JavaScript string.
safe.URLDeclares the given string 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, capitalizing the first character.
strings.HasPrefixReports whether the given string begins with the given prefix.
strings.HasSuffixReports whether the given string ends with the given suffix.
strings.RepeatReturns a new string consisting of zero or more copies of another string.
strings.ReplaceReturns a copy of INPUT, replacing all occurrences of OLD with NEW.
strings.ReplacePairsReturns a copy of a string with multiple replacements performed in a single pass, using a slice of old and new string pairs.
strings.ReplaceREReturns a copy of INPUT, 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.DeferDefer execution of a template until after 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.EmojifyRuns a string through the Emoji emoticons processor.
transform.HighlightRenders code with a syntax highlighter.
transform.HighlightCodeBlockHighlights 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.HTMLToMarkdownConverts HTML to Markdown.
transform.HTMLUnescapeReturns the given string, replacing each HTML entity with its corresponding character.
transform.MarkdownifyRenders Markdown to HTML.
transform.PlainifyReturns a string with all HTML tags removed.
transform.PortableTextConverts Portable Text to Markdown.
transform.RemarshalMarshals a string of serialized data, or a map, into a string of serialized data in the specified format.
transform.ToMathRenders mathematical equations and expressions written in the LaTeX markup language.
transform.UnmarshalParses serialized data and returns a map or an array. Supports CSV, JSON, TOML, YAML, and XML.
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.JoinPathJoins the provided elements into a URL string and cleans the result of any ./ or ../ elements. If the argument list is empty, JoinPath returns an empty string.
urls.ParseParses a URL into a URL structure.
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.
