templates: ensure template exists before trying to use it