Created
February 25, 2017 07:01
-
-
Save DejanBelic/dddd4fb0299bd41d5055eb782d001dbe to your computer and use it in GitHub Desktop.
Naming templates based on page title 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
function my_theme_theme_suggestions_page_alter(array &$suggestions, array $variables) { | |
// Naming templates based on page title. | |
if ($node = \Drupal::routeMatch()->getParameter('node')) { | |
$translation = $node->getTranslation('en'); | |
$suggestions[] = 'page__node__' . strtolower($translation->title->value); | |
$title = $node->getTitle(); | |
foreach ($suggestions as &$replace) { | |
$replace = str_replace(' ', '_', $replace); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment