Skip to content

Templates ​

Templates define the structure of components and variants. They use Go’s text/template engine along with custom template functions provided by Tempo.

📌 Default Template Functions ​

Tempo provides a set of built-in helper functions:

FunctionDescription
goPackageNameConverts a string into a valid Go package name.
goExportedNameConverts a string into a valid exported Go function name.
goUnexportedNameConverts a string into a valid unexported Go function name.
normalizePathNormalizes a path string.
isEmptyChecks if a string is empty.

📌 Built-in Template Variables ​

Tempo automatically provides a set of predefined variables that can be used inside templates. These variables come from the configuration and CLI context during execution.

VariableDescription
TemplatesDirThe root directory containing template files.
ActionsDirThe root directory containing actions files.
GoModuleThe name of the Go module being worked on.
GoPackageThe Go package name where components will be organized and generated.
ComponentNameThe name of the component being generated.
VariantNameThe name of the variant being generated (if applicable).
AssetsDirThe directory where asset files (CSS, JS) will be generated.
WithJsWhether JavaScript is required for the component (true/false).
CssLayerThe CSS layer name associated with component styles.
GuardMarkerPlaceholder used in templ files to mark auto-generated sections.

📌 Extending Template Functions ​

Tempo supports external function providers, allowing you to integrate additional helper functions into your templates.

See the full guide in Extending Tempo.