diff --git a/salix.go b/salix.go index 73bc294..5fff137 100644 --- a/salix.go +++ b/salix.go @@ -6,6 +6,7 @@ import ( "fmt" "html" "io" + "maps" "reflect" "go.elara.ws/salix/internal/ast" @@ -55,6 +56,20 @@ func New() *Template { return t.WithTagMap(defaultTags).WithFuncMap(defaultFuncs) } +// Clone returns a shallow clone of a template. +func (t *Template) Clone() *Template { + return &Template{ + file: t.file, + ast: t.ast, + + escapeHTML: t.escapeHTML, + + tags: maps.Clone(t.tags), + funcs: maps.Clone(t.funcs), + vars: maps.Clone(t.vars), + } +} + // WithFuncMap adds all the functions in m to the template's // global function map. If a function with the given name already // exists, it will be overwritten.