Skip to content

Instantly share code, notes, and snippets.

@star-szr
Created March 28, 2014 19:33
Show Gist options
  • Save star-szr/9841184 to your computer and use it in GitHub Desktop.
Save star-szr/9841184 to your computer and use it in GitHub Desktop.
Adding template suggestions for view modes and content types in Drupal 8
<?php
/**
* Implements hook_theme_suggestions_HOOK_alter() for node.html.twig.
*/
function MYTHEME_theme_suggestions_node_alter(array &$suggestions, array $variables) {
// Add template suggestions based on the current view mode.
$node = $variables['elements']['#node'];
$suggestions[] = 'node__' . $variables['elements']['#view_mode'];
$suggestions[] = 'node__' . $node->bundle() . '__' . $variables['elements']['#view_mode'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment