utils

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ScriptURL = func(path string) string {
	return path + "?v=" + ScriptVersion
}

ScriptURL generates cache-busted script URLs. Override this to use custom cache busting (CDN, content hashing, etc.)

Example override in your app:

func init() {
    utils.ScriptURL = func(path string) string {
        return myAssetManifest.GetURL(path)
    }
}
View Source
var ScriptVersion = fmt.Sprintf("%d", time.Now().Unix())

ScriptVersion is a timestamp generated at app start for cache busting. Used in component script tags to append ?v=<timestamp> to script URLs.

Functions

func ComponentScript added in v1.8.0

func ComponentScript(component string) templ.Component

ComponentScript renders a deferred script tag for a component JavaScript file. Example: ComponentScript("datepicker") → <script defer src="/templui/js/datepicker.min.js?..."></script>

func GenerateNonce

func GenerateNonce() (string, error)

func If

func If[T comparable](condition bool, value T) T

TwIf returns value if condition is true, otherwise an empty value of type T. Example: true, "bg-red-500" → "bg-red-500"

func IfElse

func IfElse[T any](condition bool, trueValue T, falseValue T) T

TwIfElse returns trueValue if condition is true, otherwise falseValue. Example: true, "bg-red-500", "bg-gray-300" → "bg-red-500"

func MergeAttributes

func MergeAttributes(attrs ...templ.Attributes) templ.Attributes

MergeAttributes combines multiple Attributes into one. Example: MergeAttributes(attr1, attr2) → combined attributes

func RandomID

func RandomID() string

RandomID generates a random ID string. Example: RandomID() → "id-1a2b3c"

func SetupScriptRoutes added in v1.8.0

func SetupScriptRoutes(mux *http.ServeMux, isDevelopment bool)

SetupScriptRoutes serves embedded component JavaScript files for the import workflow. Example: SetupScriptRoutes(mux, true) mounts /templui/js/*.min.js with no-store caching in development.

func TwMerge

func TwMerge(classes ...string) string

TwMerge combines Tailwind classes and resolves conflicts. Example: "bg-red-500 hover:bg-blue-500", "bg-green-500" → "hover:bg-blue-500 bg-green-500"

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL