Last active
June 10, 2022 13:42
-
-
Save phunguyen19/c913bee602e322f33ea63fd55fbc78dd to your computer and use it in GitHub Desktop.
drupal 8 custom page template (suggestion) based on content types (page--[content-type].html.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
<?php | |
/** | |
* Implements hook_theme_suggestions_HOOK_alter(). | |
* | |
* This hook for adding a custom suggestion page template. | |
* | |
* Place this function in your THEME_NAME.theme file. | |
* then you can use the template page--[content-type].html.twig | |
* | |
* Tested and worked with Drupal Version 8.3.x | |
*/ | |
function THEME_NAME_theme_suggestions_page_alter(array &$suggestions, array $variables) { | |
if ($node = \Drupal::routeMatch()->getParameter('node')) { | |
$content_type = $node->bundle(); | |
$suggestions[] = 'page__'.$content_type; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment