From 8dfcece8054179ec869ceb775d10d64bbf08d6d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 26 Jan 2026 21:38:50 +0100 Subject: [PATCH] Fix recently introduced partial rendering bug Fixes #14433 --- hugolib/embedded_templates_test.go | 28 ++++++++++++++++++++++++++++ tpl/templates/templates.go | 6 +++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/hugolib/embedded_templates_test.go b/hugolib/embedded_templates_test.go index c93ccdf9f..f96060ef5 100644 --- a/hugolib/embedded_templates_test.go +++ b/hugolib/embedded_templates_test.go @@ -160,3 +160,31 @@ title: p10 variant = `{{ template "_internal/pagination.html" (dict "page" . "format" "terse") }}` test(variant, expectedOutputTerseFormat) } + +func TestOpengraphPartialIssue14433(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +baseURL = "https://example.org" +-- content/_index.md -- +--- +title: Home +--- +-- layouts/home.html -- + + + +{{- partial "opengraph.html" . }} + + + + +` + b := Test(t, files) + + b.AssertFileContent("public/index.html", + ``, + `! false`, + ) +} diff --git a/tpl/templates/templates.go b/tpl/templates/templates.go index 1f1eb0ad6..5f7db243c 100644 --- a/tpl/templates/templates.go +++ b/tpl/templates/templates.go @@ -100,7 +100,7 @@ func (ns *Namespace) _PushPartialDecorator(ctx context.Context, id string) (any, } // For internal use only. -func (ns *Namespace) _PopPartialDecorator(ctx context.Context, id string) bool { +func (ns *Namespace) _PopPartialDecorator(ctx context.Context, id string) any { stack := tpl.Context.PartialDecoratorIDStack.Get(ctx) if stack == nil || stack.Len() == 0 { panic("decorator stack is nil or empty") @@ -111,6 +111,10 @@ func (ns *Namespace) _PopPartialDecorator(ctx context.Context, id string) bool { if !ok || top.Str != id { panic("partial decorator ID mismatch") } + if !top.Bool { + // Prevents anything being rendered if inner was not called. + return "" + } return top.Bool // return whether inner exists in the wrapped partial. } -- 2.39.5