Adding pager to queried content in a custom module Drupal 8 I've created a custom module to get X items using entityQuery, and then display them as a list. I need to limit these and add a pager to click through to the next page, but I cannot find how best to do this. Examples I've found either use external search sources, or are depreciated functions of older versions of Drupal.

I've added the pager option in the query, initialized the pager, and added the #type = pager to the content block, but it's not showing up. I know I am missing something but I cant figure out what it is.

class MyPageController extends ControllerBase {

public function myPage1() {


    $query = \Drupal::entityQuery('node')
    -&gt;condition('status', 1)
    -&gt;condition('type', 'page')
    -&gt;range(0, 10)
    -&gt;pager(3)
    -&gt;sort('created', 'DESC');

    $nids = $query-&gt;execute();
    $nodes = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;loadMultiple($nids);

    pager_default_initialize($query-&gt;total, '7');

    $list = array();

    foreach ($nodes AS $node){
        $list[] = $node-&gt;get('title')-&gt;value;
    }

    $content = [
        '#theme' =&gt; 'item_list',
        '#list_type' =&gt; 'ul',
        '#title' =&gt; 'Page list',
        '#items' =&gt; $list,
        '#attributes' =&gt; ['class' =&gt; 'my_page1_list'],
        '#wrapper_attributes' =&gt; ['class' =&gt; 'container'],
        '#type' =&gt; ['pager'],
    ]; 

    return $content;
}
}
The format of the render array is wrong, you have to place the pager in its own render element (see this question, which was almost at the same time Pager with EntityQuery) or if you want to have it in the theme in a variable, but then a name other than #type.