Pagination of results for use in a template