Skip to content

Commit

Permalink
Merge pull request #54 from roblillack/cbroglie-53-fix-context-stacks…
Browse files Browse the repository at this point in the history
…-for-sections

Fix building context stack for inner elements of sections
  • Loading branch information
cbroglie authored Jun 9, 2021
2 parents 2ebfd28 + 4f2dfd2 commit f01d98a
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 f01d98a

Please sign in to comment.