mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +02:00
@@ -60,29 +60,29 @@ func NewExecuter(helper ExecHelper) Executer {
|
||||
}
|
||||
|
||||
type (
|
||||
dataContextKeyType string
|
||||
pageContextKeyType string
|
||||
hasLockContextKeyType string
|
||||
stackContextKeyType string
|
||||
)
|
||||
|
||||
const (
|
||||
// The data object passed to Execute or ExecuteWithContext gets stored with this key if not already set.
|
||||
DataContextKey = dataContextKeyType("data")
|
||||
// The data page passed to ExecuteWithContext gets stored with this key.
|
||||
PageContextKey = pageContextKeyType("page")
|
||||
// Used in partialCached to signal to nested templates that a lock is already taken.
|
||||
HasLockContextKey = hasLockContextKeyType("hasLock")
|
||||
)
|
||||
|
||||
// Note: The context is currently not fully implemeted in Hugo. This is a work in progress.
|
||||
func (t *executer) ExecuteWithContext(ctx context.Context, p Preparer, wr io.Writer, data any) error {
|
||||
if ctx == nil {
|
||||
panic("nil context")
|
||||
}
|
||||
|
||||
tmpl, err := p.Prepare()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if v := ctx.Value(DataContextKey); v == nil {
|
||||
ctx = context.WithValue(ctx, DataContextKey, data)
|
||||
}
|
||||
|
||||
value, ok := data.(reflect.Value)
|
||||
if !ok {
|
||||
value = reflect.ValueOf(data)
|
||||
@@ -102,28 +102,6 @@ func (t *executer) ExecuteWithContext(ctx context.Context, p Preparer, wr io.Wri
|
||||
return tmpl.executeWithState(state, value)
|
||||
}
|
||||
|
||||
func (t *executer) Execute(p Preparer, wr io.Writer, data any) error {
|
||||
tmpl, err := p.Prepare()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
value, ok := data.(reflect.Value)
|
||||
if !ok {
|
||||
value = reflect.ValueOf(data)
|
||||
}
|
||||
|
||||
state := &state{
|
||||
helper: t.helper,
|
||||
prep: p,
|
||||
tmpl: tmpl,
|
||||
wr: wr,
|
||||
vars: []variable{{"$", value}},
|
||||
}
|
||||
|
||||
return tmpl.executeWithState(state, value)
|
||||
}
|
||||
|
||||
// Prepare returns a template ready for execution.
|
||||
func (t *Template) Prepare() (*Template, error) {
|
||||
return t, nil
|
||||
|
Reference in New Issue
Block a user