Skip to main content
this section: |

Developer toolkit

~5 m

The tk/ partials are developer utilities. Most are value-returning — they are called as $result := partial "tk/name" . and produce no HTML output. They form the asset pipeline, debug tooling, and help system that all tool/ partials build on.

Content authors do not call these. Developers writing new tool/ partials should use them rather than calling Hugo functions directly, so that the theme’s conventions (image dict contract, opt validation, debug guards) are consistently applied.


Hooks have moved

The six site-wide extension points used to live here as tk/hook-*. They are now their own folder, layouts/_partials/hook/, and are documented separately — see Layout hooks . They are the only partials a site integrator is expected to write; everything below this line is theme-internal.


Asset pipeline

These are the core image and asset resolution chain. Always call them in order rather than calling .Resources.Get, .Process, or .Fit directly.

PartialReturnsPurpose
get-asset.html$img dictResolves a path to a normalised $img dict (page resource / assets/ / static/) — gold standard. Pass noPublish when you will process res yourself, so the original is not published
img-process.html$img dictApplies a Hugo process string or slice of strings to a resource; returns updated $img
date-offset.htmlstringOffsets a time by a w/d/h/m string and formats it; ordinal format gives 7<sup>th</sup>
get-width-height.htmldict "w" int "h" intParses a Hugo process string to extract target dimensions
resource-image-featured.html$img dict or 0Resolves the featured image for a page using get-asset and img-process
path-image-featured.htmlstringReturns the RelPermalink of the first resource matching FeaturedGlob

The $img dict fields returned by get-asset:

FieldTypeNotes
srcstringRelative permalink — always safe in src=
resresourceHugo resource object, or 0 for static fallback
mediaTypestringMIME type e.g. image/svg+xml
isSvgbool
isRasterboolpng/jpg/webp/tiff/bmp — excludes gif
isGifboolMay be animated — process with care
isVideobool
isImageboolConvenience: isSvg or isRaster or isGif
isStaticboolFrom static/ — no resource object, no processing possible
widthintNative px width after any processing; 0 for SVG/video/static
heightintNative px height
altstringAlt text; caller-supplied or basename of asset
captionstringCaption text; "" if not supplied

Site data utilities

PartialReturnsPurpose
get-defaults.htmlmapParsed assets/data/defaults.yaml — component default class names
get-logo.html$imgThe site logo as an $img dict — ui.logo, else assets/brand/logo.svg, else logo.png; takes .process and .noPublish
get-logo-path-string.htmlstringSite logo src path via get-logo, resized by .process when the logo is a raster in assets/. The logo is expected in assets/ (unset: assets/brand/logo.svg, else logo.png) — a static/ logo resolves but cannot be resized or packed into favicons
get-theme-version.htmlstringInstalled pihuw version from hugo.Deps (the consumer’s go.mod pin); "" on a local replacement

Opt validation

PartialReturnsPurpose
opt-validate.htmldictParses and validates an opt JSON string against a schema string; returns ok, opts, errors, errorMsg

See the opt-validate reference below.

Debug utilities

These emit output and are not value-returning. They must be guarded with {{- if hugo.IsServer -}} and must never be called inside value-returning partials.

PartialPurpose
dbg-template.htmlHTML comment showing the current template name — server only
dbg-template-comment.htmlAlternate template comment emitter
dbg.htmlKey-value debug panel rendered as a visible <div> — server only
Debug.htmlCalls hugo.Log "DEBUG" — server only
Debugf.htmlFormatted debug log — server only
Warnf.htmlFormatted warning log — server only
Errorf.htmlFormatted error log — server only
templateList.htmlReturns the template hierarchy as a string — server only
pageList.htmlReturns the page hierarchy as a string — server only
kvListNoPage.htmlReturns context dict without page keys — server only

Help system

These build the inline help cards rendered by help = "yes" shortcodes. Developers writing a new tool should create a peer -help.html file using these partials.

PartialPurpose
help.htmlEntry point for {{&lt; hw t = "help" >}} — calls all registered tool help partials
help-tk.htmlInjects the CSS and JavaScript needed to show help modals
help-card.htmlWraps help content in a dismissible modal trigger
help-header.htmlRenders the shortcode usage line and parameter summary
help-description.htmlRenders the description and feature bullet list
help-params.htmlRenders the parameter reference table
help-examples.htmlRenders copy-pasteable code examples
help-notes.htmlRenders notes, tips, and warnings

Registering a new tool’s help in {{&lt; hw t = "help" >}} requires adding its name to the $tools slice in tk/help.html.


opt-validate

opt-validate validates an opt JSON string from a shortcode against a developer-supplied JSON schema string. It is called at the top of any tool partial that accepts an opt parameter.

1
2
3
4
5
6
7
8
{{- $v := partial "tk/opt-validate" (dict
    "schema" `{"mode!": "compact", "count": 0, "no-auto-tag": false}`
    "opt"    .opt
    "tool"   "my-tool") -}}
{{- if and (not $v.ok) hugo.IsServer -}}
  <div>{{ $v.errorMsg | safeHTML }}</div>
{{- end -}}
{{- $opts := $v.opts -}}

Schema syntax: keys ending in ! are required; the value encodes the expected type and default (false/true → bool, 0 → number, any string → string).

Error IDs: SCHEMA invalid schema · JP JSON parse failure · FK:{key} unknown key · MK:{key} missing required key · TY:{key} type mismatch

Squashing errors: add "squash": "FK:foo MK:bar" to the opt string to suppress specific error IDs. Use "squash": "*" (hero mode) to suppress all errors during schema development — a loud warning banner is shown in server mode and it must be removed before publishing.