Articles


How to set up variables for a specific type to use in a Template Drupal 8?

How to set up variables for a specific type to use in a Template Drupal 8?



Posted bysivaprasad,21st Nov 2016

It's almost the same as in Drupal 7, but in Drupal 8 the concept changes as OOP. So there is some difference to call the 'type'.

We can't simply call the type, we have to get the value of the type by function 'getType()'.


function THEME_NAME_preprocess_node(&$variables) {
  if (!empty($variables['node']) && $variables['node']->getType() == 'my-type') {
    $variables['title'] = 'MY TITLE';
  }
}

Related Articles