aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl/partials
diff options
context:
space:
mode:
authorPaul Gottschling <[email protected]>2021-12-17 02:35:21 -0500
committerGitHub <[email protected]>2021-12-17 08:35:21 +0100
commit5758c370eac6c4460cd6bb34d4475c8d347585f6 (patch)
tree8a9f337cf38ed842a1d011f46d43f0e58768fd5a /tpl/partials
parent8ee6de6d96a64395d27416d4f2ad7d172a2686d0 (diff)
downloadhugo-5758c370eac6c4460cd6bb34d4475c8d347585f6.tar.gz
hugo-5758c370eac6c4460cd6bb34d4475c8d347585f6.zip
Allow for return partials with falsy arguments (#9298)
Partials with returns values are parsed, then inserted into a partial return wrapper via wrapInPartialReturnWrapper in order to assign the return value via *contextWrapper.Set. The predefined wrapper template for partials inserts a partial's nodes into a "with" template action in order to set dot to a *contextWrapper within the partial. However, because "with" is skipped if its argument is falsy, partials with falsy arguments were not being evaluated. This replaces the "with" action in the partial wrapper with a "range" action that isn't skipped if .Arg is falsy. Fixes #7528
Diffstat (limited to 'tpl/partials')
-rw-r--r--tpl/partials/partials.go5
1 files changed, 0 insertions, 5 deletions
diff --git a/tpl/partials/partials.go b/tpl/partials/partials.go
index e8a8adc36..b0dc0a997 100644
--- a/tpl/partials/partials.go
+++ b/tpl/partials/partials.go
@@ -25,7 +25,6 @@ import (
"strings"
"sync"
- "github.com/gohugoio/hugo/common/hreflect"
texttemplate "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate"
"github.com/gohugoio/hugo/helpers"
@@ -121,10 +120,6 @@ func (ns *Namespace) Include(name string, contextList ...interface{}) (interface
var w io.Writer
if info.HasReturn {
- if !hreflect.IsTruthful(context) {
- // TODO(bep) we need to fix this, but it is non-trivial.
- return nil, errors.New("partial that returns a value needs a non-zero argument.")
- }
// Wrap the context sent to the template to capture the return value.
// Note that the template is rewritten to make sure that the dot (".")
// and the $ variable points to Arg.