{{- $paginator := . -}}

{{- if gt $paginator.TotalPages 1 -}}

{{- $pageIndex := $paginator.PageNumber -}}
{{- $totalPages := $paginator.TotalPages -}}
{{- $cols := 5.0 -}}
{{- $rows := math.Ceil (div $totalPages $cols) -}}
{{- $row := math.Ceil (div $pageIndex $cols) -}}
{{- $startPage := sub (mul $row $cols) $cols -}}
{{- $endPage := add $startPage $cols -}}

<div class="pagination">
    <ul>
        {{- if gt $row 1 -}}
            <li><a href="{{- $paginator.Prev.URL -}}"><span class="iconfont icon-pagepreview"></span></a></li>
        {{- end -}}

        {{- range $paginator.Pagers -}}
            {{- if and (gt .PageNumber $startPage) (le .PageNumber $endPage) -}}
                {{- $active := "" -}}
                {{- if eq .PageNumber $paginator.PageNumber -}}
                    {{- $active = "active" -}}
                {{- end -}}
                <li><a class="{{- $active -}}" href="{{- .URL -}}">{{- .PageNumber -}}</a></li>
            {{- end -}}
        {{- end -}}

        {{- if lt $row $rows -}}
            <li><a href="{{- $paginator.Next.URL -}}"><span class="iconfont icon-pagenext"></span></a></li>
        {{- end -}}
    </ul>
</div>
{{- end -}}