Programmatically render a panels page variant There is a Page with id: front_page, and a number of variants.

I want to programmatically load the page, evaluate the context and render the appropriate variant.

I have the following code to load the page:

$page_id = 'featured_content';
$page_storage = \Drupal::entityTypeManager()-&gt;getStorage('page');
$variant_storage = \Drupal::entityTypeManager()-&gt;getStorage('page_variant');
$page = $page_storage-&gt;load($page_id);
// ...


How can I build or render the $page?
Here is how :

$page = \Drupal\page_manager\Entity\Page::load('featured_content');
//all variants ids, for the example
$variants = $page-&gt;getVariants();
$variantIds = array_keys($variants);
// last variant... could have been $page-&gt;getVariant('{VARIANT_ID}');
$pageVariant = end($variants);
$viewer = new \Drupal\page_manager\Entity\PageVariantViewBuilder();
$arr = $viewer-&gt;view($pageVariant);
\Drupal::service('renderer')-&gt;render($arr);