Check Content Type in Page PreProcess Hook I'm attempting to get the content type in my page preprocess function...but apparently I'm missing something.  What am I doing wrong here?  I'm attempting to get the $node variables first - then test from there.

function mytheme_preprocess_page(&amp;$variables) {
   $node = \Drupal::routeMatch()-&gt;getParameter('node');
   switch ($node-&gt;getType()) {
       case "client":
           $variables['attributes']['class'][] = 'clientpage';
       break;
        case "something_else":
           // ...
       break;
   }    
 }
Instead of looking at the route parameter, you can also do:

$node = $variables['node'];

Here is some example code that I have that is working from preprocess_page:

    $node = $variables['node'];

    if ($node instanceof NodeInterface) {
      $type = $node-&gt;getType();

      if ($type == 'listing_page' &amp;&amp; trim($node-&gt;getTitle()) == 'News') {
        $variables['is_news_page'] = TRUE;
      }
    }


Don't forget your use ... statement if you check node is NodeInterface.

So this is definitely doable - if you are getting any error messages please post them and double check your content type machine names.