I've created a custom Drupal 7 block view that uses a mini pager. I need to display the pager-previous and pager-next links as images, and replace the pager-current link with some text. Do I need to create templates for these three links? Do I need preprocess functions for each of them? What are the naming conventions for these templates and functions? They would be tied to a particular block display.
1 Answer
For the mini pager, the Views module uses its own theme function, theme_views_mini_pager()
, which uses the more generic theme functions for the previous, next, and current links. There isn't a template file for that theme function, as the theme function itself is returning the markup.
With hook_preprocess_views_pager()
, you could change the values contained in $vars['tags'][1]
and $vars['tags'][3]
, which by default are the '‹‹'
and '››'
, but those are passed to a theme function, which means you are someway limited in what you can do.
$li_previous = theme('pager_previous', array(
'text' => isset($tags[1]) ? $tags[1] : t('‹‹'),
'element' => $element,
'interval' => 1,
'parameters' => $parameters,
));
if (empty($li_previous)) {
$li_previous = " ";
}
$li_next = theme('pager_next', array(
'text' => isset($tags[3]) ? $tags[3] : t('››'),
'element' => $element,
'interval' => 1,
'parameters' => $parameters,
));
if (empty($li_next)) {
$li_next = " ";
}
$items[] = array(
'class' => array(
'pager-previous',
),
'data' => $li_previous,
);
$items[] = array(
'class' => array(
'pager-current',
),
'data' => t('@current of @max', array(
'@current' => $pager_current,
'@max' => $pager_max,
)),
);
$items[] = array(
'class' => array(
'pager-next',
),
'data' => $li_next,
);
You can implement hook_theme_registry_alter()
to replace that theme function with your own. In this case, you have complete control over the output; you could even tell Drupal to use a template file.
Keep in mind that theme_views_mini_pager()
is used for mini pager of every view. For what I can see, there isn't any value passed in $vars
that makes understand for which view the mini pager is output.
Given the lack of documentation on the values passed in $vars
, I would check what is passed in $vars
. It may be that one of those values is the view ID, or machine name.
The values documented in the theme functions for the previous, next, and current links are the following.
- element: An optional integer to distinguish between multiple pagers on one page
- interval: The number of pages to move backward when the link is clicked
- parameters: An associative array of query string parameters to append to the pager links
-
Thanks, kiamaluno, that's just what I needed. You're right, there is no way to identify the view and display ids from passed vars. In my case, it's ok because I just use the view on one page, and can get it from $_GET and create customizations for that one page. Much appreciated!– pglatzCommented Feb 27, 2021 at 20:16