Skip to content

Instantly share code, notes, and snippets.

@fredysan
Created April 5, 2021 20:38
Show Gist options
  • Save fredysan/211eef2839b811102f0785ffcdeb135f to your computer and use it in GitHub Desktop.
Save fredysan/211eef2839b811102f0785ffcdeb135f to your computer and use it in GitHub Desktop.
Theme Suggestions

Theme template suggestions.

Page template suggestions per node bundle

/**
 * Implements hook_theme_suggestions_page_alter().
 */
function my_module_theme_suggestions_page_alter(array &$suggestions, array $variables) {
  $node_revision = \Drupal::routeMatch()->getParameter('node_revision');
  $node = $node_revision
    ? \Drupal::entityTypeManager()->getStorage('node')->loadRevision($node_revision)
    : \Drupal::routeMatch()->getParameter('node');

  if ($node instanceof NodeInterface) {
    $content_type = $node->bundle();
    $suggestions[] = 'page__'.$content_type;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment