Road to Drupal 8

PHP -> Symfony -> Drupal 8

Page template dependiendo del tipo de contenido

D8 Version

 

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function THEMENAME_theme_suggestions_page_alter(array &$suggestions, array $variables) {
  if ($node = \Drupal::routeMatch()->getParameter('node')) {
    $suggestions[] = 'page__' . $node->getType();
  }
  return $suggestions;
}

D7 Version

 

function themename_preprocess_page(&$variables) {
  if (!empty($variables['node']) && !empty($variables['node']->type)) {
    $variables['theme_hook_suggestions'][] = 'page__node__' . $variables['node']->type;
  }
}

D6 Version

 

function themename_preprocess_page(&$variables) {
  if (!empty($variables['node']) && !empty($variables['node']->type)) {
    $variables['template_files'][] = "page-node-" . $variables['node']->type;
  }
}