Reference for the custom string, math, date, and data functions registered into Sarde's template engine
Sarde registers custom functions into Go's html/template engine. Call them with standard template syntax: {{ funcName arg1 arg2 }} or pipe an argument with {{ arg1 | funcName }}.
Truncates to n runes, appending ... when truncated. Returns a hard cut when n < 3.
slugify
slugify(s string) string
Converts to a URL-safe slug. urlize is an alias.
replace
replace(s, old, new string) string
Replaces all occurrences of a substring
split
split(s, sep string) []string
Splits a string by separator
join
join(list []string, sep string) string
Joins a string slice with separator
contains
contains(s, substr string) bool
Substring containment check
hasPrefix
hasPrefix(s, prefix string) bool
Prefix check
hasSuffix
hasSuffix(s, suffix string) bool
Suffix check
trim
trim(s string) string
Trims leading and trailing whitespace
markdownify
markdownify(v any) HTML
Renders a value as inline Markdown (GFM). Strips the wrapping <p> tag from single-paragraph input.
plainify
plainify(s string) string
Strips all HTML tags, returning plain text
safeHTML
safeHTML(s string) HTML
Marks a string as safe, unescaped HTML
highlight
highlight(code, lang string) HTML
Wraps code in <pre><code class="language-X">. This is a lightweight stub, not full syntax highlighting.
Math
All math functions accept any numeric type. Results stay as int when both operands are integer types, float64 otherwise. Division and modulo by zero return 0.
Function
Signature
Description
add
add(a, b any) any
Addition
sub
sub(a, b any) any
Subtraction
mul
mul(a, b any) any
Multiplication
div
div(a, b any) any
Division (truncates toward zero for integer operands)
mod
mod(a, b any) int
Integer modulo
Logic
Function
Signature
Description
cond
cond(condition bool, trueVal, falseVal any) any
Ternary conditional
default
default(value, fallback any) any
Returns fallback when value is nil or its type's zero value
isset
isset(m map[string]any, key string) bool
Checks key existence in a map
Collections
Function
Signature
Description
first
first(n int, list any) any
First n elements of a slice
last
last(n int, list any) any
Last n elements
after
after(n int, list any) any
All elements after index n
shuffle
shuffle(list any) any
Returns a randomly-shuffled copy
sortBy
sortBy(list any, field string) any
Stable sort by a struct/map field value. Comparison is string-based.
where
where(list any, field string, value any) any
Filters elements where field equals value. Uses fmt.Sprint for comparison.
group
group(list any, field string) map[string]any
Groups elements into a map keyed by field value
uniq
uniq(list any) any
Deduplicates by string representation, preserving first occurrence
in
in(list any, value any) bool
Membership test
seq
seq(args ...int) []int
Generates an integer sequence. seq(n) produces [1..n]. seq(start, end) produces an inclusive range.
HTML
{{ $tutorials := where .Pages "Type" "tutorial" }}
{{ $sorted := sortBy $tutorials "Title" }}
{{ $byCategory := group .Pages "Category" }}
URLs
Function
Signature
Description
absURL
absURL(path string) string
Resolves a path to an absolute URL using the site's base URL
relURL
relURL(path string) string
Resolves a path to a relative URL. Passes through paths already containing ://.
editURL
editURL(base, relPath string) string
Joins a base "edit this page" URL with a relative content path
Assets
Function
Signature
Description
asset
asset(path string) string
Resolves an asset path to its /assets/ URL
fingerprint
fingerprint(path string) string
Returns the content-hashed output URL for a path
inline
inline(path string) HTML
Inlines file content. Wraps .css in <style> and .js in <script>.
getResource
getResource(resources []Resource, name string) *Resource
Reads a string from a param map, returning "" when missing
renderHeadTags
renderHeadTags(tags []HeadTag) HTML
Renders head tags into <head> markup. Filters by allowed tag names.
renderAttrs
renderAttrs(attrs map[string]string) HTML
Renders a map as sorted, escaped HTML attributes
versionOf
versionOf(page *Page, versionID string) *Page
Finds the version peer of a page matching the given version ID
toString
toString(v any) string
Converts any value to its string representation
toInt
toInt(v any) int
Converts a numeric value to int. Returns 0 for non-numeric values.
Debug and data
Function
Signature
Description
dump
dump(value any) HTML
Renders %+v representation in a <pre> block
jsonify
jsonify(value any) HTML
Pretty-prints a value as indented JSON
printf
printf(format string, args ...any) string
Standard Go string formatting (fmt.Sprintf)
data
data(name string) any
Loads a data file from the project's data/ directory. Accepts .yaml, .yml, .json, or .toml (first match wins). Cached per build.
Templates
Function
Signature
Description
partial
partial(name string, data any) HTML
Renders a cached partial template by name
component
component(name string, data any) HTML
Renders a registered component by name
themeStyles
themeStyles(data *RouteData) HTML
Emits <link> and/or <style> tags for the token CSS and main CSS bundle. See Theme Tokens.
announcementBanner
announcementBanner() HTML
No-op stub. Overridden by the announcements plugin when enabled.
Dates
Function
Signature
Description
dateFormat
dateFormat(t time.Time, layout string) string
Formats a time using a Go layout string. Uses Go's reference-date convention ("January 2, 2006"), not strftime tokens.
now
now() time.Time
Returns the current time
Shortcode availability
Shortcode templates run during parallel Markdown rendering and receive a reduced function map. All functions not listed below work identically in shortcodes.
Function
Status
Notes
component
No-op
Returns an empty string (component registry unavailable)
partial
Errors
Returns "partial cache not initialized"
Plugin functions
Absent
Plugin-registered functions are not merged into the shortcode map
t, tWithData
Degraded
Return the key unchanged (i18n string table unavailable)
absURL, relURL
Degraded
Available but not language-aware (URL resolver unavailable)
themeStyles
Degraded
Emits inline <style> only, not external <link> tags