Skip to content

Instantly share code, notes, and snippets.

@neetumorwani
Forked from gwagroves/module.php
Created April 5, 2018 07:59
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 neetumorwani/df49159bb3fe137aef53a128f7fbb394 to your computer and use it in GitHub Desktop.
Save neetumorwani/df49159bb3fe137aef53a128f7fbb394 to your computer and use it in GitHub Desktop.
Drupal 8 Paragraphs: Add a theme suggestion based on the paragraph and the type of the current node.
<?php
/**
* Implements theme_suggestions_HOOK_alter().
*/
function mytheme_theme_suggestions_paragraph_alter(array &$suggestions, array $variables) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$paragraph = $variables['elements']['#paragraph'];
array_push($suggestions, 'paragraph__' . $paragraph->getType() . '__' . $node->getType());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment