Can't output pager or pagination using entity query drupal 8

I’m currently in the middle of trying to output the pagination or pager using entity query. I’ve been reading samples and tutorials but I can’t seem to make it display on my twig file. I’m not sure what I’m missing here. I’m currently using drupal 8

// Entity Query for News
//////////////////////////////////////////////////


$newsPostings = $query->get('node')
    ->condition('status', 1, '=')
    ->condition('type', 'article')
    ->sort('created', 'desc')
    ->pager(9)
    ->execute();

foreach ($newsPostings as $key => $news_postings) {

    $newsNode = _nodeLoad($news_postings);


    $publishDate = strtotime($newsNode->get('created')->value);
    $articleCreated = date('F j, Y', $publishDate);


    $variables['article'][$key]['title'] = $newsNode->get('title')->value;
    $variables['article'][$key]['image'] = $newsNode->field_image->entity->url();
    $variables['article'][$key]['path'] = $newsNode->toUrl();
    $variables['article'][$key]['date'] = $articleCreated;
}

// Pager for News Entity Query
//////////////////////////////////////////////////
$nodesNews =  \Drupal\node\Entity\Node::loadMultiple($newsPostings);
$pathNews = base_path();

$build['pager'] = [
    '#theme' => 'page__news',
    '#items' => $nodesNews,
    '#path'  => $pathNews,
    '#pager' => [
        '#type' => 'pager',
      ],
  ];

      
  return $build;

I don’t have experience using Drupal 8 but when I used 6/7 I found the only way to make sense of all that complexity is to use smart debugging tools like xdebug to step through code line by line. I would highly recommend beginning there.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.