]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix recently introduced partial rendering bug
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 26 Jan 2026 20:38:50 +0000 (21:38 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 26 Jan 2026 21:45:16 +0000 (22:45 +0100)
Fixes #14433

hugolib/embedded_templates_test.go
tpl/templates/templates.go

index c93ccdf9fa36837dcc3dca025e37f71d6a45ee93..f96060ef5943ee90d83389f0b08868c4bf9e13f8 100644 (file)
@@ -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 --
+<!DOCTYPE html>
+<html lang="en">
+<head>
+{{- partial "opengraph.html" . }}
+</head>
+<body>
+</body>
+</html>
+`
+       b := Test(t, files)
+
+       b.AssertFileContent("public/index.html",
+               `<meta property="og:title" content="Home">`,
+               `! false`,
+       )
+}
index 1f1eb0ad682355f6a8c72267d1942aa00242a542..5f7db243c46539ab320eeb96d9cb307c51dcec2b 100644 (file)
@@ -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.
 }