take care inverted sections in templates

take care inverted sections in templates with related test cases