Last active
October 24, 2020 00:47
-
-
Save robdecker/a395c858641d986a33bc9f1b73e817f9 to your computer and use it in GitHub Desktop.
[Paragraph variables] #d8 #twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# This paragraph's parent (either a node or a paragraph) #} | |
{% set parent = paragraph._referringItem.parent.parent.entity %} | |
{# A field's entity #} | |
{% set entity = paragraph.field_item.get(0).entity %} | |
{# Media Library image #} | |
<img src="{{ file_url(paragraph.field_media.0.entity.field_media_image.entity.uri.value) }}"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_theme_suggestions_HOOK_alter(). | |
*/ | |
function THEME_theme_suggestions_paragraph_alter(array &$suggestions, array $variables) { | |
$elements = $variables['elements']; | |
$paragraph = $elements['#paragraph']; | |
$parent = $paragraph->getParentEntity(); | |
if ($parent) { | |
$suggestions[] = 'paragraph__' . $parent->bundle() . '__' . $paragraph->bundle(); | |
$suggestions[] = 'paragraph__' . $parent->bundle() . '__' . $paragraph->bundle() . '__' . $elements['#view_mode']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment