Skip to content

Commit

Permalink
sections: Fix building context stack for inner elements of sections. #53
Browse files Browse the repository at this point in the history
  • Loading branch information
roblillack committed Jun 7, 2021
1 parent 2ebfd28 commit 4f2dfd2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mustache.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ func renderSection(section *sectionElement, contextChain []interface{}, buf io.W
if err != nil {
return err
}
var context = contextChain[len(contextChain)-1].(reflect.Value)
var context = contextChain[0].(reflect.Value)
var contexts = []interface{}{}
// if the value is nil, check if it's an inverted section
isEmpty := isEmpty(value)
Expand Down
18 changes: 18 additions & 0 deletions mustache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ var tests = []Test{
"categories": {&Category{"a", "b"}},
}, "a - b", nil},

{`{{#section}}{{#bool}}{{x}}{{/bool}}{{/section}}`,
map[string]interface{}{
"x": "broken",
"section": []map[string]interface{}{
{"x": "working", "bool": true},
{"x": "nope", "bool": false},
},
}, "working", nil},

{`{{#section}}{{^bool}}{{x}}{{/bool}}{{/section}}`,
map[string]interface{}{
"x": "broken",
"section": []map[string]interface{}{
{"x": "working", "bool": false},
{"x": "nope", "bool": true},
},
}, "working", nil},

//dotted names(dot notation)
{`"{{person.name}}" == "{{#person}}{{name}}{{/person}}"`, map[string]interface{}{"person": map[string]string{"name": "Joe"}}, `"Joe" == "Joe"`, nil},
{`"{{{person.name}}}" == "{{#person}}{{{name}}}{{/person}}"`, map[string]interface{}{"person": map[string]string{"name": "Joe"}}, `"Joe" == "Joe"`, nil},
Expand Down

0 comments on commit 4f2dfd2

Please sign in to comment.