From 9dd04d0af6f97a9c6f1f9ab174d2e531fb88d525 Mon Sep 17 00:00:00 2001 From: Andre Lehmann Date: Fri, 22 Apr 2022 19:31:02 +0200 Subject: [PATCH] Expose the template lexical context --- render/context.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/render/context.go b/render/context.go index bae220a..ea0dceb 100644 --- a/render/context.go +++ b/render/context.go @@ -12,6 +12,8 @@ import ( // Context provides the rendering context for a tag renderer. type Context interface { + // Bindings returns the current lexical environment. + Bindings() map[string]interface{} // Get retrieves the value of a variable from the current lexical environment. Get(name string) interface{} // Errorf creates a SourceError, that includes the source location. @@ -75,6 +77,11 @@ func (c rendererContext) EvaluateString(source string) (out interface{}, err err return expressions.EvaluateString(source, expressions.NewContext(c.ctx.bindings, c.ctx.config.Config.Config)) } +// Bindings returns the current lexical environment. +func (c rendererContext) Bindings() map[string]interface{} { + return c.ctx.bindings +} + // Get gets a variable value within an evaluation context. func (c rendererContext) Get(name string) interface{} { return c.ctx.bindings[name]