diff --git a/eval.go b/eval.go index 7683f4e..111e723 100644 --- a/eval.go +++ b/eval.go @@ -702,8 +702,17 @@ func (v *evalVisitor) partialContext(node *ast.PartialStatement) reflect.Value { } if node.Hash != nil { + // mix the hash parameters and the current context into one map hash, _ := node.Hash.Accept(v).(map[string]interface{}) - return reflect.ValueOf(hash) + curCtx, _ := v.curCtx().Interface().(map[string]interface{}) + newCtx := make(map[string]interface{}) + for k, v := range curCtx { + newCtx[k] = v + } + for k, v := range hash { + newCtx[k] = v + } + return reflect.ValueOf(newCtx) } return zero diff --git a/partial.go b/partial.go index 3299d02..d959113 100644 --- a/partial.go +++ b/partial.go @@ -62,6 +62,22 @@ func RegisterPartialTemplate(name string, tpl *Template) { partials[name] = newPartial(name, "", tpl) } +// RemovePartial removes the partial registered under the given name. The partial will not be available globally anymore. This does not affect partials registered on a specific template. +func RemovePartial(name string) { + partialsMutex.Lock() + defer partialsMutex.Unlock() + + delete(partials, name) +} + +// RemoveAllPartials removes all globally registered partials. This does not affect partials registered on a specific template. +func RemoveAllPartials() { + partialsMutex.Lock() + defer partialsMutex.Unlock() + + partials = make(map[string]*partial) +} + // findPartial finds a registered global partial func findPartial(name string) *partial { partialsMutex.RLock()