diff options
author | Bjørn Erik Pedersen <[email protected]> | 2023-02-25 09:24:59 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-02-25 19:53:18 +0100 |
commit | ce524d0b5ebaef05d29fa368465f31358f26dcda (patch) | |
tree | e5df54a5deeefacbff4916d3619f85c2cb341b01 /tpl/template.go | |
parent | 2662faf61ff0240be1ee0d6c496b6b4a6ed55fb4 (diff) | |
download | hugo-ce524d0b5ebaef05d29fa368465f31358f26dcda.tar.gz hugo-ce524d0b5ebaef05d29fa368465f31358f26dcda.zip |
Add a page template func
Fixes #9339
Diffstat (limited to 'tpl/template.go')
-rw-r--r-- | tpl/template.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tpl/template.go b/tpl/template.go index dd9249ade..f71de8bb2 100644 --- a/tpl/template.go +++ b/tpl/template.go @@ -59,7 +59,6 @@ type UnusedTemplatesProvider interface { // TemplateHandler finds and executes templates. type TemplateHandler interface { TemplateFinder - Execute(t Template, wr io.Writer, data any) error ExecuteWithContext(ctx context.Context, t Template, wr io.Writer, data any) error LookupLayout(d output.LayoutDescriptor, f output.Format) (Template, bool, error) HasTemplate(name string) bool @@ -153,10 +152,18 @@ type TemplateFuncGetter interface { GetFunc(name string) (reflect.Value, bool) } -// GetDataFromContext returns the template data context (usually .Page) from ctx if set. -// NOte: This is not fully implemented yet. -func GetDataFromContext(ctx context.Context) any { - return ctx.Value(texttemplate.DataContextKey) +// GetPageFromContext returns the top level Page. +func GetPageFromContext(ctx context.Context) any { + return ctx.Value(texttemplate.PageContextKey) +} + +// SetPageInContext sets the top level Page. +func SetPageInContext(ctx context.Context, p page) context.Context { + return context.WithValue(ctx, texttemplate.PageContextKey, p) +} + +type page interface { + IsNode() bool } func GetHasLockFromContext(ctx context.Context) bool { |