I am trying to see if we are on a view page in the preprocess_page function in my MYTHEME.theme file.

views_get_page_view() gives me an undefined function error.

I want to get values from my view to display outside the view area in page.html.twig

1 Answer 1


That function will error because it does not exist in Drupal 8.

You can do this though:

$view_id = \Drupal::routeMatch()->getParameter('view_id');
$view = \Drupal\views\Views::getView($view_id);

Be sure to validate view_id first though, that it exists/length before calling the second line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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