How to set page/content title/header from a controller I have a custom route and module that outputs content to a page.

I want to also have a page/content title/header on the page. I've figured out how to set the browser title, but I can't figure out how to add the headline title.

When creating a basic page with no custom template, the headline is part of that html. I want to replicate this.

Here is what I have in my controller:

return array(
    '#title' =&gt; 'This sets the browser title',
    '#markup' =&gt; 'This is the html output',
);


I've been banging my head on this for a few days now... help!

I've already tried setting $variables['title'] in theme_preprocess_page_title, but that doesn't seem to get called. I've also tried it in preprocess_page, but that does nothing.

To clarify - I am wanting to change the text that is by default displayed in &lt;h1 class="page-header"&gt; from within my controller.
You set the title in the route in the _title parameter:

mymodule.page:
  path: '/mymodule/page'
  defaults:
    _title: 'Page title'
    _controller: '\Drupal\mymodule\Controller\MyController::controller'


Or you can use a route callback:

mymodule.page:
  path: '/mymodule/page'
  defaults:
    _title_callback: '\Drupal\mymodule\Controller\MyController::title'
    _controller: '\Drupal\mymodule\Controller\MyController::controller'


And then put the title callback in the controller class, which receives the same parameters as the controller, so that you can determine a title on that information.