Created
July 1, 2021 11:08
-
-
Save Oleksii909/86ef4cebd08831322c9f184e2da695de to your computer and use it in GitHub Desktop.
add theme suggestions
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
/** | |
* Implements hook_theme_suggestions_HOOK_alter() for block templates. | |
*/ | |
function custom_theme_suggestions_node_alter(array &$suggestions, array $variables) { | |
$element = $variables['elements']; | |
// 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']; | |
} | |
/** | |
* Implements hook_theme_suggestions_HOOK_alter() for block templates. | |
*/ | |
function custom_theme_suggestions_field_alter(array &$suggestions, array $variables) { | |
$element = $variables['element']; | |
// Add template suggestions based on the current view mode. | |
$field_name = $variables['element']['#field_name']; | |
$suggestions[] = 'field__' . $variables['element']['#view_mode']; | |
$suggestions[] = 'field__' . $field_name . '__' . $variables['element']['#view_mode']; | |
} | |
/** | |
* Implements hook_theme_suggestions_HOOK_alter() for block templates. | |
*/ | |
function custom_theme_suggestions_block_alter(array &$suggestions, array $variables) { | |
if (isset($variables['elements']['content']['#block_content'])) { | |
$suggestions[] = 'block__' . $variables['elements']['content']['#block_content']->bundle(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment