Functions
This page documents the built-in functions available for use in your template files. These functions can be called directly within your Go templates to insert and transform data, perform checks, or parse values.
Note
The current set of helper functions is limited, more functions may be added in the future. If you need additional helper functions, feel free to request it!
Parsing (String Conversion)¶
These functions help you to convert your inserted data to the correct type.
Note
All external input (e.g. environment) values start as strings.
parseBool¶
Parses a string as a boolean value.
Syntax¶
Examples¶
Usage¶
parseInt¶
Parses a string as an integer.
Syntax¶
Examples¶
Usage¶
parseFloat¶
Parses a string as a floating-point number.
Syntax¶
Examples¶
Usage¶
parseTime¶
Parses a string as a time value using the specified layout.
Syntax¶
Examples¶
Usage¶
| Template | |
|---|---|
| Output | |
|---|---|
Formatting (String Conversion)¶
These functions help you to convert values to their string representations.
formatBool¶
Formats a boolean value as a string.
Syntax¶
Examples¶
formatInt¶
Formats an integer value as a string in the given base.
Syntax¶
Examples¶
formatFloat¶
Formats a floating-point value as a string with the given format, precision, and bit size.
Syntax¶
Examples¶
formatTime¶
Formats a time value using the specified layout.
Syntax¶
Examples¶
| Template | |
|---|---|
| Output | |
|---|---|
String¶
These functions help you to transform your inserted data.
lower¶
Converts a string to lowercase.
Syntax¶
Examples¶
Usage¶
upper¶
Converts a string to uppercase.
Syntax¶
Examples¶
Usage¶
split¶
Splits a string into a slice using the given separator.
Syntax¶
Examples¶
Usage¶
replace¶
Replaces all occurrences of a substring with another substring. The last argument is the number of replacements to make. Use -1 to replace all occurrences.
Syntax¶
Examples¶
Usage¶
File System¶
exists¶
Checks if a file or directory exists at the given path.
Syntax¶
Examples¶
Usage¶
Tip
To access environment variables within your templates, use the dedicated env function or its .Env variable counterpart.
For details and examples, see the dedicated Environments page.