Zope ZPT Pagination of any list object

Code to paginate the looped display of any result listing, for example, from a catalog search.
tal:define="listingAll python: context.portal_catalog.searchResults(portal_type = 'MyType');
	currentPage python: int(request.get('page', '1'));
	totalListings python: len(listingAll );
	listingsPerPage python: 3;
	offset python: (currentPage - 1) * listingsPerPage ;
	showPrev python: (currentPage > 1);
	showNext python: totalListings > (currentPage * listingsPerPage );
	listings python: listingAll[ offset : offset + listingsPerPage ];">
				
<!-- display mycontent here -->
<div id="paginate" tal:condition="python: listingsPerPage < totalListings">
	<a tal:attributes="href python: template.id + '?page=' + str(currentPage - 1)" tal:condition="showPrev">Prev</a> 
	<a tal:attributes="href python: template.id + '?page=' + str(currentPage + 1)" tal:condition="showNext">Next</a> 
</div>
Snippet Viewed 1845 times.

Share your Zope ZPT code snippets:

  • Get some recognition & a link back to your site.
  • Create your own code library.
  • Help your fellow developers, as they have helped you.

 

Submit | Browse

Most Recent zope zpt snippets

Most Viewed