Skip to content

Instantly share code, notes, and snippets.

@gwagroves
Last active April 7, 2024 13:02
Show Gist options
  • Save gwagroves/58156593ef87c815d4bed6a86f0bf370 to your computer and use it in GitHub Desktop.
Save gwagroves/58156593ef87c815d4bed6a86f0bf370 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 parent node / entity.
<?php
/**
* Implements theme_suggestions_HOOK_alter().
*/
function mytheme_theme_suggestions_paragraph_alter(array &$suggestions, array $variables) {
/** @var \Drupal\paragraphs\ParagraphInterface $paragraph */
$paragraph = $variables['elements']['#paragraph'];
/** @var \Drupal\Core\Entity\ContentEntityInterface $parent */
$parent = $paragraph->getParentEntity();
$suggestions[] = 'paragraph__' . $paragraph->bundle() . '__' . $parent->bundle();
}
@gwagroves
Copy link
Author

@macherif Good call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment