Showing entries range number on pagination

I want to share the code to display the number of entries range on the pager.

{{ $ThisElements := .Paginator.NumberOfElements }}
{{ $TotalElements := .Paginator.TotalNumberOfElements }}
{{ $CurrentPage := .Paginator.PageNumber }}
{{ $PageSize := .Paginator.PageSize }}

{{ if gt $paginator.TotalPages 1 }}
<div class="container">
Showing
{{ if eq (sub $PageSize $ThisElements) 0 }}
{{ if eq $CurrentPage 1 }}
<!-- First pager -->
{{ $CurrentPage }}
{{ else }}
<!-- Regular pager -->
{{ add (mul (sub $CurrentPage 1) $PageSize) 1 }}
{{ end }}
to {{ mul $PageSize $CurrentPage }}
{{ else }}
<!-- Last Pager -->
{{ add (sub $TotalElements $ThisElements) 1 }} to {{ $TotalElements }}
{{ end }}
 of {{ $TotalElements }} entries
</div>
{{ end }}

image

Hope it is useful

9 Likes