Pager with EntityQuery how can I make a pager with the pager class? I could not find anywhere how to do this with the EntityQuery class. I have a pager(10) that displays the last 10 items. I want to make a pager with numbers like
&lt; 1, 2, 3, 4, 5, 6 >.

This is the code I have now:

class NewsArchive extends BlockBase {

  /**
   * {@inheritdoc}
   */
  public function build() {

    // Query for newest articles and return max 3 results.
    $query = \Drupal::entityQuery('node');
    $news = $query-&gt;condition('type', 'news')
      -&gt;condition('status', 1)
      -&gt;sort('created', 'DESC')
      -&gt;pager(10)
      -&gt;execute();

    // LoadMultiple News in $nodes variable
    $nodes = Node::loadMultiple($news);

    $path = base_path();

    // Return $nodes variable with name items to the module.
    return array(
      '#theme' =&gt; 'mytheme_news_archive',
      '#items' =&gt; $nodes,
      '#path'  =&gt; $path,
    );

  }
}


I have read somewhere that this was possible with the following code:

      $build['pager'] = [
        '#type' =&gt; 'pager',
      ];


How does this build pager (render) fit into my code? Can someone show me how to start?
Add the pager to the build array in which you return the results:

  return [
    'results' =&gt; [
      '#theme' =&gt; 'mytheme_news_archive',
      '#items' =&gt; $nodes,
      '#path'  =&gt; $path,
    ],
    'pager' =&gt; [
      '#type' =&gt; 'pager',
    ],
  ];    


Or extend the theme with a variable #pager if you want to theme this in one place:

  return [
    'results' =&gt; [
      '#theme' =&gt; 'mytheme_news_archive',
      '#items' =&gt; $nodes,
      '#path'  =&gt; $path,
      '#pager' =&gt; [
        '#type' =&gt; 'pager',
      ],
    ],
  ];    


Then you can print the pager in twig:

{{ pager }}