Keyword modifier for next page number in asset listing


(Oliver Kass) #1

Trying to get a keyword going to print the number of the next page below the next button in an asset listing but can’t get it too work. Currently going with something like this in order to include additional html and classes:

<li class="next">
  %next_page^replace_keywords:notempty:<a href="{next_page_href}">Next <span class="visuallyhidden">page</span><span class="page-numbers">{page_number} of {total_pages}</span></a>%
</li>

Which works perfectly and means my pagination only shows when the next button is visible. So far so good. However, was thinking I could just use another modifier to add 1 to each page number but it doesn’t work:

<li class="next">
  %next_page^replace_keywords:notempty:<a href="{next_page_href}">Next <span class="visuallyhidden">page</span><span class="page-numbers">{page_number^add:1} of {total_pages}</span></a>%
</li>

As you would expect this works out side of my main keyword:

%page_number^add:1% of %total_pages%

Can’t help but thinking I’m either missing something obvious or taking the wrong approach here…


(Peter McLeod) #2

Hi
maybe something like:

%begin_page_number^lt:{total_pages}%
  <li class="next"><a href="%next_page_href%">Next <span class="visuallyhidden">page</span> <span class="page-numbers">%page_number^add:1% of %total_pages%</span></a></li>
%end_page_number%

or %begin_page_number^replace_keywords:lt:{total_pages}% for pre 5.4 versions

Thanks
Peter


(Oliver Kass) #3

Thanks very much Peter. This got me on the right track. Ended up with this as a solution as needed to take into account previous page too:

<ul class="pagination-list col-lg-12">
    %begin_previous_page^replace_keywords:notempty:{previous_page}%
        <li class="prev">
            <a href="%previous_page_href%">Previous <span class="visuallyhidden">page</span> <span class="page-numbers">%page_number^subtract:1% of %total_pages%</span></a>
        </li>
    %end_previous_page%

    %begin_next_page^replace_keywords:notempty:{next_page}%
        <li class="next">
            <a href="%next_page_href%">Next <span class="visuallyhidden">page</span> <span class="page-numbers">%page_number^add:1% of %total_pages%</span></a>
        </li>
    %end_next_page%
</ul>