Fix bug in getting template from file or function