From f75d81385c5f041bf5293523f0014c2e3789ecef Mon Sep 17 00:00:00 2001 From: Marco Gazerro Date: Sat, 21 Feb 2026 22:57:41 +0100 Subject: [PATCH] internal/compiler: fix macro statement rendering Update template statement emission so macro calls used as standalone statements render to the current output format instead of being discarded. --- internal/compiler/emitter_statements.go | 12 ++++++++++++ test/misc/multi_file_template_test.go | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/internal/compiler/emitter_statements.go b/internal/compiler/emitter_statements.go index cffea906f..7fdfe974c 100644 --- a/internal/compiler/emitter_statements.go +++ b/internal/compiler/emitter_statements.go @@ -389,6 +389,18 @@ func (em *emitter) emitNodes(nodes []ast.Node) { } case ast.Expression: + // In templates, a macro call used as statement (for example + // `{% Content() %}` in an extending layout) must render directly to + // the current output format instead of discarding its result. + // Non-macro expressions keep the previous behavior. + if call, ok := node.(*ast.Call); ok { + if fn := em.ti(call.Func); fn != nil && fn.IsMacroDeclaration() { + em.fb.enterStack() + em.emitCallNode(call, false, false, em.fb.fn.Format) + em.fb.exitStack() + continue + } + } em.fb.enterStack() em.emitExprR(node, reflect.Type(nil), 0) em.fb.exitStack() diff --git a/test/misc/multi_file_template_test.go b/test/misc/multi_file_template_test.go index bbdf860e0..9ec4f3fe8 100644 --- a/test/misc/multi_file_template_test.go +++ b/test/misc/multi_file_template_test.go @@ -2250,6 +2250,21 @@ func TestMultiFileTemplate(t *testing.T) { expectedOut: "foo", }, + "Using - show in Content block with extends and markdown": { + sources: fstest.Files{ + "layout.html": `{% Content() %}`, + "macro.html": `{% macro M(s markdown) %}{% if s %}{{ s }}{% end %}{% end %}`, + "index.html": ` + {% extends "layout.html" %} + {% import "macro.html" %} + {% Content %}{% show M(itea); using markdown %} + # title + hello + {% end using %}`, + }, + expectedOut: "--- start Markdown ---\n\n\t\t\t\t\t# title\n\t\t\t\t\thello\n\t\t\t\t\t--- end Markdown ---\n", + }, + "Using - show - Two using statement": { sources: fstest.Files{ "index.txt": `{% show itea; using %}foo{% end using %}{% show itea; using %}bar{% end using %}`,