Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions internal/compiler/emitter_statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 15 additions & 0 deletions test/misc/multi_file_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": `<html><body>{% Content() %}</body></html>`,
"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: "<html><body>--- 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</body></html>",
},

"Using - show - Two using statement": {
sources: fstest.Files{
"index.txt": `{% show itea; using %}foo{% end using %}{% show itea; using %}bar{% end using %}`,
Expand Down