How to programmatically render a view pager? I'm trying to figure out how to render a view's pager programmatically. I'm renderering my view programmatically as follows:

$viewname = 'example_view';
$viewdisplay = 'block';

// get the view machine id
$view = Views::getView($viewname);
// set the display machine id
$view-&gt;setDisplay($viewdisplay);
$view-&gt;render();

$renderer = $view-&gt;rowPlugin;
foreach ($view-&gt;result as $index =&gt; $row) {
  $view-&gt;row_index = $index;
  $vars['content']['view_results'][$index] = $renderer-&gt;render($row);
}


So now I need to render the pager, but not having any luck. I've tried something like:

$pagerrenderer = $view-&gt;pager;
$vars['content']['view_pager'] = $pagerrenderer-&gt;render($view-&gt;pager);


but then end up with the following error:


  Recoverable fatal error: Argument 1 passed to pager_query_add_page()
  must be of the type array, object given, called in
  /www/projectname/docroot/core/includes/pager.inc on line 246 and defined
  in pager_query_add_page() (line 311 of core/includes/pager.inc).


Can anyone point me in the right direction?
The object returned from $views-&gt;pager() is an object implementing ViewsPluginInterface and extending PagerPluginBase. If you look at the parameters PagerPluginBase::render() accepts, you will see they are:


  $input: Any extra GET parameters that should be retained, such as exposed input.


If you look at Full::render(), you have an idea of how that parameter is used.

  $tags = array(
    0 =&gt; $this-&gt;options['tags']['first'],
    1 =&gt; $this-&gt;options['tags']['previous'],
    3 =&gt; $this-&gt;options['tags']['next'],
    4 =&gt; $this-&gt;options['tags']['last'],
  );
  return array(
    '#theme' =&gt; $this-&gt;themeFunctions(),
    '#tags' =&gt; $tags,
    '#element' =&gt; $this-&gt;options['id'],
    '#parameters' =&gt; $input,
    '#quantity' =&gt; $this-&gt;options['quantity'],
    '#route_name' =&gt; !empty($this-&gt;view-&gt;live_preview) ? '&lt;current&gt;' : '&lt;none&gt;',
  );


In any case, you don't pass to the method of that object the object itself.