The route name of the current page is available in page.html.twig? The page is generated by the default feedback form.


To get the current route name, use:

$route_name = \Drupal::routeMatch()->getRouteName();

You can add the current page's route name as a variable in your theme's ".theme" file. Add a _preprocess_page function like this, and clear the drupal cache.

 * Implements hook_preprocess_page().
function mytheme_preprocess_page(&$variables) {
  $variables['route_name'] = \Drupal::routeMatch()->getRouteName();

Then you can access in page.html.twig like this:

{{ route_name }}

Note: \Drupal::routeMatch()->getRouteName() will sometimes return null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.