Skip to content

Instantly share code, notes, and snippets.

@phunguyen19
Last active June 10, 2022 13:42
Show Gist options
  • Save phunguyen19/c913bee602e322f33ea63fd55fbc78dd to your computer and use it in GitHub Desktop.
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)
<?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