tpl: Allow the partial template func to return any type

This commit adds support for return values in partials.

This means that you can now do this and similar:

    {{ $v := add . 42 }}
    {{ return $v }}

Partials without a `return` statement will be rendered as before.

This works for both `partial` and `partialCached`.

Fixes #5783
This commit is contained in:
Bjørn Erik Pedersen
2019-04-02 10:30:24 +02:00
committed by GitHub
parent 9225db636e
commit a55640de8e
11 changed files with 371 additions and 79 deletions

View File

@@ -22,10 +22,17 @@ type Info struct {
// Set for shortcode templates with any {{ .Inner }}
IsInner bool
// Set for partials with a return statement.
HasReturn bool
// Config extracted from template.
Config Config
}
func (info Info) IsZero() bool {
return info.Config.Version == 0
}
type Config struct {
Version int
}