Added template logic to pagination buttons