diff --git a/eval.go b/eval.go index 6528c9c..f3a8a7e 100644 --- a/eval.go +++ b/eval.go @@ -126,6 +126,34 @@ func (st *Runtime) YieldBlock(name string, context interface{}) { st.executeList(block.List) } +// YieldTemplate yields a template same as include +func (st *Runtime) YieldTemplate(name string, context interface{}) { + + t, err := st.set.GetTemplate(name) + if err != nil { + panic(fmt.Errorf("include: template %q was not found: %s", name, err)) + } + + st.newScope() + st.blocks = t.processedBlocks + + Root := t.Root + if t.extends != nil { + Root = t.extends.Root + } + + if context != nil { + c := st.context + st.context = reflect.ValueOf(context) + st.executeList(Root) + st.context = c + } else { + st.executeList(Root) + } + + st.releaseScope() +} + func (st *scope) getBlock(name string) (block *BlockNode, has bool) { block, has = st.blocks[name] for !has && st.parent != nil {