Change page title from Views preprocess function I want to be able to change the main page title based on some value that I get in a views preprocess function.

The View is displayed as a page.

function MYTHEME_preprocess_views_view(&amp;$variables) {

  // Can I set the page title from here?
}


The title I am trying to override is the title printed by the /templates/content/page-title.html.twig below:

{#
/**
 * @file
 * Theme override for page titles.
 *
 * Available variables:
 * - title_attributes: HTML attributes for the page title element.
 * - title_prefix: Additional output populated by modules, intended to be
 *   displayed in front of the main title tag that appears in the template.
 * - title: The page title, for use in the actual content.
 * - title_suffix: Additional output populated by modules, intended to be
 *   displayed after the main title tag that appears in the template.
 */
#}
{{ title_prefix }}
{% if title %}
  &lt;h1{{ title_attributes }}&gt;{{ title }}&lt;/h1&gt;
{% endif %}
{{ title_suffix }}
I don't think hook_preprocess_views_view() or hook_preprocess_page_title() is good ways in your case. You can use hook_views_pre_render

/**
 * Implements hook_views_pre_render().
 */
function MYMODULE_views_pre_render(ViewExecutable $view) {

  if ($view-&gt;id() == 'VIEW_ID') {
    $arg = $view-&gt;args; // Argument from view. 
    $default_title = $view-&gt;getTitle(); // Get view title.
    $view-&gt;setTitle('New title'); // Set new title
  }
}


All variables you need in here.