Jquery Render Template with Conditions and Loop