diff options
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/internal/templatefuncsRegistry.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/tpl/internal/templatefuncsRegistry.go b/tpl/internal/templatefuncsRegistry.go index 363f6d82f..eea14372b 100644 --- a/tpl/internal/templatefuncsRegistry.go +++ b/tpl/internal/templatefuncsRegistry.go @@ -170,14 +170,17 @@ func (namespaces TemplateFuncsNamespaces) MarshalJSON() ([]byte, error) { buf.WriteString("{") for i, ns := range namespaces { - if i != 0 { - buf.WriteString(",") - } + b, err := ns.toJSON(context.TODO()) if err != nil { return nil, err } - buf.Write(b) + if b != nil { + if i != 0 { + buf.WriteString(",") + } + buf.Write(b) + } } buf.WriteString("}") @@ -202,6 +205,11 @@ func (t *TemplateFuncsNamespace) toJSON(ctx context.Context) ([]byte, error) { if err != nil { return nil, err } + if tctx == nil { + // E.g. page. + // We should fix this, but we're going to abandon this construct in a little while. + return nil, nil + } ctxType := reflect.TypeOf(tctx) for i := 0; i < ctxType.NumMethod(); i++ { method := ctxType.Method(i) |