Hide first and last buttons on second and second last pages

Based on this guide, how can the code be re-written to:

  1. Hide the first page button when on the second page.
  2. Hide the last page button while on the second last page.

The reason for this is because a warning is thrown by the wave accessibility testing tool about redundant links (since in both cases, the previous and first page buttons and the next and last page buttons point to the same links in second page and second last page respectively).

  1. If possible, how would the code be re-written so that the partial is called without the dict part? I.e. {{ partial "pagination.html" . }} (this is not as important.)

Not really what I want or described. FYI, your navigation code raises the same issue on redundant links.

You are correct. I have removed my non-helpful answer.

No problem. I am assuming I will need a condition. I just don’t know which one to call second page and second last page.

I worked on it a little more.

To find the first or second page, in which case the “first page” link goes away or is grayed-out:

{{ if and (ne $paginator.PageNumber 1) (ne $paginator.PageNumber 2) }}

. . . and, to find the next-to-last and last page, in which case the “last page” link goes away or is grayed-out:

{{ if (and ( (ne $paginator.PageNumber $paginator.TotalPages) ) (ne $paginator.PageNumber (sub $paginator.TotalPages 1))) }}

Perhaps that also isn’t what you want, but I ran each scenario through WAVE and got no messages about redundant links on any of the four pages (first, second, next-to-last, or last).

1 Like

I noticed the warnings are not limited to those two pages. If, for example, the pagination is showing three numbered pages (2, 3, 4) and it has a previous and next page buttons, the latter will still throw a warning about redundant links e.g. when on page 3. I have never thought to check that before in pagination.

Update: I limited the links to only the active link per page. ({{- $slots := 1 }} from the linked pagination terse code)

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.