Refactor the template logic into more-route-if