Drupal 8 Theme suggestions for node preview page

1k views Asked by At

We have content types with panel and panelizer enabled. We have added theme suggestions for content view page as follows.

function HOOK_theme_suggestions_page_alter(array &$suggestions, array $variables) {
    $node = \Drupal::routeMatch()->getParameter('node');
    if(!empty($node)){
        $type = $node->getType();
        if($type == 'abc'){
            $suggestions[] = 'page__abc';            
        }
   }
}

The defined template file is coming for node view page. But when we check for node preview this "page--abc.html.twig" is not coming. Node preview page rendering by page.html.twig.

Please guide me how to make this "page--abc.html.twig" for node preview. Thanks in advance.

1

There are 1 answers

0
Quan Lee On

you can read hook template_preprocess_node

  if ($variables['view_mode']) {
    $variables['theme_hook_suggestions'][] = 'node__' . $variables['view_mode'];
  }