Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Oleksii909/86ef4cebd08831322c9f184e2da695de to your computer and use it in GitHub Desktop.
Save Oleksii909/86ef4cebd08831322c9f184e2da695de to your computer and use it in GitHub Desktop.
add theme suggestions
/**
* 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