In a custom module I have a block defined and the function that builds the block returns a render array. In that render array I am looking to create a pager for my content since it is a listing of items.
If I run pager_default_initialize during my query building like so this automatically adds a pager to the top of the block.
$total = $query->countQuery()
->execute()
->fetchField();
$page = pager_default_initialize($total, $per);
$query->extend('PagerDefault')
->limit($per)
->range($page * $per, $per);
I want to have more control over the pager, like adding it to the bottom of the block. If I remove the pager_default_initialize
from the query building code like so, I can stop the pager from automatically being added.
$total = $query->countQuery()
->execute()
->fetchField();
$page = pager_find_page();
$query->extend('PagerDefault')
->limit($per)
->range($page * $per, $per);
So, the question is, how do I add the pager to my render array so it renders the pager at the bottom of the block?
My render array currently looks like this:
$content['results'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => 'results',
),
);
if ($data->rowCount()) {
foreach ($data as $record) {
$content['results'][] = array(
'#theme' => 'CUSTOM_NODE_THEME',
'#node' => node_load($record->nid),
);
}
if ($per > 0) {
$content['results']['pager'] = array(
'#theme' => 'pager',
);
}
}
The theme_pager() is not being run when the block is rendered.
Any help would be awesome!