Skip to content

Instantly share code, notes, and snippets.

@frederickjh
Created July 3, 2017 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frederickjh/bf71d5b1bcd80466b77a83b87a00bc5f to your computer and use it in GitHub Desktop.
Save frederickjh/bf71d5b1bcd80466b77a83b87a00bc5f to your computer and use it in GitHub Desktop.
This the code is from the "DrupalCon Baltimore 2017: Demystifying Rendered Content in Drupal 8 Twig Files" presentation by Amy Vaillancourt-Sals slide 30 "Create a custom file name suggestion". It adds Twig templates for block bundles.
/**
* This code is from the "DrupalCon Baltimore 2017: Demystifying Rendered Content in Drupal 8 Twig Files" presentation by Amy Vaillancourt-Sals slide 30 "Create a custom file name suggestion".
* Video: https://www.youtube.com/watch?v=qoeRpRkGwmk
* Slides: https://drive.google.com/file/d/0B8g8dQw8nc9eV3U4SjZKNWNEWGM/view?usp=sharing
* Drupalcon Baltimore Session: https://events.drupal.org/baltimore2017/sessions/demystifying-rendered-content-drupal-8-twig-files
* This code adds Twig templates for block bundles. Replace "themename" below with your theme's machine name.
* Implements hook_theme_suggestions_HOOK_alter() for templates.
* @param array $suggestions
* @param array $variables
*/
function themename_theme_suggestions_block_alter(array &$suggestions, array $variables) {
// Block suggestions for custom block bundles.
if (isset($variables['elements']['content']['#block_content'])) {
array_splice($suggestions, 1,0, 'block__type__' . $variables['elements']['content']['#block_content']->bundle());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment