PaginatedArray::renderPager()

Render pagination

This method renders pagination for PageArray, PaginatedArray, or any class extending either of those. Use the $options argument to customize the output.

Usage

// basic usage
$string = $paginatedArray->renderPager();

// usage with all arguments
$string = $paginatedArray->renderPager(array $options = []);

Arguments

NameType(s)Description
$options (optional)array

Options to modify default markup, classes, labels, etc.

  • numPageLinks (int): Number of links that the pagination navigation should have, minimum 5 Default:10
  • getVars (array): Get vars that should appear in the pagination, or leave empty and populate $input->whitelist (preferred) Default:[]
  • baseUrl (string): The baseUrl from which the navigation item links will start Default:''
  • page (Page|null): The current Page, or leave NULL to autodetect Default:null
  • listMarkup (string): List container markup. Place {out} where you want the individual items rendered Default:<ul class='{class}' role='navigation' aria-label='{aria-label}'>{out}</ul>
  • listClass (string): Class attribute for the pagination list Default:'MarkupPagerNav'
  • itemMarkup (string): List item markup. Place '{class}' for item class (required), and '{out}' for item content Default:<li aria-label='{aria-label}' class='{class}' {attr}>{out}</li>
  • separatorItemMarkup (string|null): Item separator "...", null makes it use the itemMarkup instead Default:null
  • linkMarkup (string): Link markup. Place '{url}' for href attribute, and '{out}' for label content Default:<a href='{url}'><span>{out}</span></a>
  • currentLinkMarkup (string): Link markup for current page. Place '{url}' for href attribute and '{out}' for label content Default:<a href='{url}'><span>{out}</span></a>
  • nextItemLabel (string): Label used for the 'Next' button Default:'Next'
  • previousItemLabel (string): Label used for the 'Previous' button Default:'Prev'
  • separatorItemLabel (string): Label used in the separator item Default:'…'
  • separatorItemClass (string): Class used for list item separator Default:'MarkupPagerNavSeparator'
  • firstItemClass (string): Class used for first item Default:'MarkupPagerNavFirst'
  • firstNumberItemClass (string): Class used for first numbered nav item Default:'MarkupPagerNavFirstNum'
  • nextItemClass (string): Class used for "next" nav item Default:'MarkupPagerNavNext'
  • previousItemClass (string): Class used for "previous" nav item Default:'MarkupPagerNavPrevious'
  • lastItemClass (string): Class added to last nav item Default:'MarkupPagerNavLast'
  • lastNumberItemClass (string): Class added to last numbered nav item Default:'MarkupPagerNavLastNum'
  • currentItemClass (string): Class added to current/active nav item Default:'MarkupPagerNavOn'
  • currentItemExtraAttr (string): Any extra attributes for current item Default:aria-current='true'
  • listAriaLabel (string): Aria label for list <ul> Default:'Pagination links'
  • itemAriaLabel (string): Aria label for list item <li> Default:'Page {n}'
  • currentItemAriaLabel (string): Aria label for current list item Default:'Page {n}, current page'
  • nextItemAriaLabel (string): Aria label for "next" nav item Default:'Next page'
  • previousItemAriaLabel (string): Aria label for "prev" nav item Default:'Previous page'
  • lastItemAriaLabel (string): Aria label for last nav item Default:'Page {n}, last page'

Return value

string


Hooking PaginatedArray::renderPager(…)

You can add your own hook events that are executed either before or after the PaginatedArray::renderPager(…) method is executed. Examples of both are included below. A good place for hook code such as this is in your /site/ready.php file.

Hooking before

The 'before' hooks are called immediately before each PaginatedArray::renderPager(…) method call is executed. This type of hook is especially useful for modifying arguments before they are sent to the method.

$this->addHookBefore('PaginatedArray::renderPager', function(HookEvent $event) {
  // Get the object the event occurred on, if needed
  $PaginatedArray = $event->object;

  // Get values of arguments sent to hook (and optionally modify them)
  $options = $event->arguments(0);

  /* Your code here, perhaps modifying arguments */

  // Populate back arguments (if you have modified them)
  $event->arguments(0, $options);
});

Hooking after

The 'after' hooks are called immediately after each PaginatedArray::renderPager(…) method call is executed. This type of hook is especially useful for modifying the value that was returned by the method call.

$this->addHookAfter('PaginatedArray::renderPager', function(HookEvent $event) {
  // Get the object the event occurred on, if needed
  $PaginatedArray = $event->object;

  // An 'after' hook can retrieve and/or modify the return value
  $return = $event->return;

  // Get values of arguments sent to hook (if needed)
  $options = $event->arguments(0);

  /* Your code here, perhaps modifying the return value */

  // Populate back return value, if you have modified it
  $event->return = $return;
});

PaginatedArray methods and properties

API reference based on ProcessWire core version 3.0.261