diff --git a/include_tag.go b/include_tag.go index 5a99fde..d2ebb03 100644 --- a/include_tag.go +++ b/include_tag.go @@ -29,8 +29,17 @@ func (it includeTag) Run(tc *TagContext, block, args []ast.Node) error { return tc.PosError(args[0], "invalid first argument type: %T (expected string)", val) } + ignoreMissing := false + if name[0] == '?' { + name = name[1:] + ignoreMissing = true + } + tmpl, ok := tc.t.ns.GetTemplate(name) if !ok { + if ignoreMissing { + return nil + } return tc.PosError(args[0], "no such template: %q", name) } diff --git a/macro_tag.go b/macro_tag.go index edc6f99..80097eb 100644 --- a/macro_tag.go +++ b/macro_tag.go @@ -20,6 +20,12 @@ func (mt macroTag) Run(tc *TagContext, block, args []ast.Node) error { return tc.PosError(args[0], "invalid first argument type: %T (expected string)", nameVal) } + ignoreMissing := false + if name[0] == '?' { + name = name[1:] + ignoreMissing = true + } + if len(block) == 0 { local := map[string]any{} @@ -40,6 +46,9 @@ func (mt macroTag) Run(tc *TagContext, block, args []ast.Node) error { macro, ok := tc.t.macros[name] if !ok { + if ignoreMissing { + return nil + } return tc.PosError(tc.Tag, "no such macro: %q", name) } return tc.Execute(macro, local)