I can't seem to figure out how to get all this information in one line in a views template.

<div class="pagination--totals">
  Page @current_page of @page_count <small>(@total Results Results)</small>

I can get the total result with {{ view.pager.total_items }}. I can get the current page with {{ view.pager.current_page }}. I can't get the page count, though.

I can get the page count in a preprocess function for the pager, but that doesn't really get me the value I need, where I need it.

 * Implements hook_preprocess_HOOK().
function acc2019_preprocess_pager(array &$variables) {
  // @see globals.api.php
  global $pager_total;

  $element = $variables['pager']['#element'];

  // Get the max page number for the current pager.
  $variables['pager_max'] = $pager_total[$element];

I can't seem to figure out how to get that value in my views-view.html.twig template in any way.

Can anyone help?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.