diff --git a/helper.go b/helper.go index eb766c3..b71782b 100644 --- a/helper.go +++ b/helper.go @@ -116,7 +116,7 @@ func (options *Options) ValueStr(name string) string { // Ctx returns current evaluation context. func (options *Options) Ctx() interface{} { - return options.eval.curCtx() + return options.eval.curCtx().Interface() } // diff --git a/helper_test.go b/helper_test.go index ccfab9b..b867e3f 100644 --- a/helper_test.go +++ b/helper_test.go @@ -163,3 +163,31 @@ func TestHelper(t *testing.T) { launchTests(t, helperTests) } + +// +// Fixes: https://github.com/aymerick/raymond/issues/2 +// + +type Author struct { + FirstName string + LastName string +} + +func TestHelperCtx(t *testing.T) { + RegisterHelper("template", func(name string, options *Options) SafeString { + context := options.Ctx() + + template := name + " - {{ firstName }} {{ lastName }}" + result, _ := Render(template, context) + + return SafeString(result) + }) + + template := `By {{ template "namefile" }}` + context := Author{"Alan", "Johnson"} + + result, _ := Render(template, context) + if result != "By namefile - Alan Johnson" { + t.Errorf("Failed to render template in helper: %q", result) + } +}