Last active
November 24, 2021 16:54
-
-
Save LittleCoding/f3b392dabe1ada23b31d3d3e089ce6a1 to your computer and use it in GitHub Desktop.
Adding template suggestions for page by node types in Drupal 8
This file contains 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 | |
/** | |
* Implementation of hook_theme_suggestions_HOOK_alter() for page.html.twig. | |
*/ | |
function MYTHEME_theme_suggestions_page_alter(array &$suggestions, array $variables) { | |
// Add template suggestions based on the current node entity content type. | |
$key = array_search('page__node', $suggestions); | |
if ($key !== FALSE && ($node = \Drupal::routeMatch()->getParameter('node'))) { | |
$content_type = $node->bundle(); | |
array_splice($suggestions, ++$key, 0, array('page__node_type__%', 'page__node_type__'.$content_type)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment