Hooks
In Drupal, hooks are the main way to interact with the Drupal core.
Templates - hooks that interact with templates
Create template suggestions
function THEMENAME_theme_suggestions_page_alter(array &$suggestions, array $variables){
$suggestions[] = 'page__roads'; //page--roads.html.twig
}Add current path as css class
$current_path = \Drupal::service('path.current')->getPath();
$path_alias = \Drupal::service('path_alias.manager')->getAliasByPath($current_path);
$path_alias = ltrim($path_alias, '/');
$variables['attributes']['class'][] = 'path-' . \Drupal\Component\Utility\Html::cleanCssIdentifier($path_alias);Get current language
$parameters = \Drupal::routeMatch()->getParameters()->all();
$variables['language'] = \Drupal::languageManager()->getCurrentLanguage();
$variables['language'] = \Drupal::languageManager()->getCurrentLanguage()->getId();Get base path
Last updated