aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl/template.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-02-25 09:24:59 +0100
committerBjørn Erik Pedersen <[email protected]>2023-02-25 19:53:18 +0100
commitce524d0b5ebaef05d29fa368465f31358f26dcda (patch)
treee5df54a5deeefacbff4916d3619f85c2cb341b01 /tpl/template.go
parent2662faf61ff0240be1ee0d6c496b6b4a6ed55fb4 (diff)
downloadhugo-ce524d0b5ebaef05d29fa368465f31358f26dcda.tar.gz
hugo-ce524d0b5ebaef05d29fa368465f31358f26dcda.zip
Add a page template func
Fixes #9339
Diffstat (limited to 'tpl/template.go')
-rw-r--r--tpl/template.go17
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 {