Add a query to check if template exists