Change view title programmatically I couldnt find an answer to this question in Drupal 8.

I've created a simple custom module: 

mymodule.info.yml

name: 'mymodule_name'
description: 'basic module for custom implementations'
package: 'custom'
type: module
version: '8.x-1.0'
core: '8.x'


mymodule.module

function mymodule_views_post_execute(\Drupal\views\ViewExecutable $view) {
    $view-&gt;setTitle('Foo');

}
function mymodule_views_pre_render(\Drupal\views\ViewExecutable $view) {
    $view-&gt;setTitle('Foo');
}


I tried this hook implementations separately, not at smae time. Both changes the view title, but my custom theme doesnt work.

I also tried in my custom theme the following code:

function mytheme_preprocess_views_view(&amp;$variables) {
    $view = $variables['view'];
    $view-&gt;build_info["title"] = "Foo";
}


It prints "Foo" inside view content, it doesnt override view title.

Any idea?
You probably want to change the global title used for the title block. This is retrieved from the route. The route for a view is built from the view configuration when you save a view  (or clear the cache). The title in the route is static. If you want to change it, modify it in the view configuration. You can do this in ui or in code.

If you want to make this dynamically, you can replace the static _title in the view route with a title controller _title_callback to provide a different title on every request.