diff --git a/mustache.go b/mustache.go index d304fdb..2815ca1 100644 --- a/mustache.go +++ b/mustache.go @@ -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) diff --git a/mustache_test.go b/mustache_test.go index 836dbe4..09f9f97 100644 --- a/mustache_test.go +++ b/mustache_test.go @@ -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},