diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-08-01 18:12:36 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-08-03 20:00:57 +0200 |
commit | ade7ec818798c0e5507d4fb6cc5b4396262a85d6 (patch) | |
tree | fe1e2e18922b20286113d66e171dfecc861d30ff /tpl | |
parent | 8fa8ce3e48c8812daa1eecc8865b653336d98147 (diff) |
Add Page.RenderShortcodes
A layouts/shortcodes/include.html shortcode may look like this:
```html
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
```
Fixes #7297
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/internal/go_templates/texttemplate/hugo_template.go | 10 | ||||
-rw-r--r-- | tpl/template.go | 8 |
2 files changed, 15 insertions, 3 deletions
diff --git a/tpl/internal/go_templates/texttemplate/hugo_template.go b/tpl/internal/go_templates/texttemplate/hugo_template.go index acfa2f166..78be55e18 100644 --- a/tpl/internal/go_templates/texttemplate/hugo_template.go +++ b/tpl/internal/go_templates/texttemplate/hugo_template.go @@ -60,9 +60,10 @@ func NewExecuter(helper ExecHelper) Executer { } type ( - pageContextKeyType string - hasLockContextKeyType string - stackContextKeyType string + pageContextKeyType string + hasLockContextKeyType string + stackContextKeyType string + callbackContextKeyType string ) const ( @@ -70,6 +71,9 @@ const ( PageContextKey = pageContextKeyType("page") // Used in partialCached to signal to nested templates that a lock is already taken. HasLockContextKey = hasLockContextKeyType("hasLock") + + // Used to pass down a callback function to nested templates. + CallbackContextKey = callbackContextKeyType("callback") ) // Note: The context is currently not fully implemented in Hugo. This is a work in progress. diff --git a/tpl/template.go b/tpl/template.go index 91a482c25..70fdf2d3d 100644 --- a/tpl/template.go +++ b/tpl/template.go @@ -191,6 +191,14 @@ func SetHasLockInContext(ctx context.Context, hasLock bool) context.Context { return context.WithValue(ctx, texttemplate.HasLockContextKey, hasLock) } +func GetCallbackFunctionFromContext(ctx context.Context) any { + return ctx.Value(texttemplate.CallbackContextKey) +} + +func SetCallbackFunctionInContext(ctx context.Context, fn any) context.Context { + return context.WithValue(ctx, texttemplate.CallbackContextKey, fn) +} + const hugoNewLinePlaceholder = "___hugonl_" var ( |