Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down