Using a module controller to create a page that is more than just a div from the twig template? I am using a custom module to create a new page on my Drupal 8 site.

My routing.yml file is configured like this:

mymodule.print:
  path: '/print-mymodule'
  defaults:
    _controller: \Drupal\mymodule\Controller\MymodulePrintController::content
  requirements:
    _permission: 'view mymodule entity'
  options:
    _auth: ['basic_auth']


MymodulePrintController::content is as follows:

public function content() {
    return array(
        '#type' =&gt; 'page',
        '#theme' =&gt; 'mytheme'
    );
}


mytheme is used everywhere else on my site.

In mytheme.theme, I also have a mytheme_preprocess() function which is adding some blocks to the page. I am guessing the theme is being detected properly because this function is executing just fine. The template I am using is named according to twig's suggestions and is loading fine.

The problem is that the content() function is not really outputting a "page". Using Postman, I see that the entire contents of the response is just a div, there is no &lt;html&gt; tag, no &lt;head&gt;, no &lt;body&gt;, nothing else except what is defined in the one twig file and mytheme_preprocess. I need this page to be using this theme's css styles like the rest of my pages are.

How can I accomplish this? Every guide/question I've seen on the topic so far either is just returning a render array in the content() function like I already am doing, or is suggesting to use Response classes without enough detail for me to really understand.
When you generate an entity with drupal console you get a twig template for the content of the entity. This is not a page and not a theme. If you want to use a page template, that is specific to the entity, then you use a template name suggestion, for exampe page--myentity.html.twig. The content from the entity controller will end up like any other content inside of this page in the region content if you use the standard block layout, where the block "Main page content" is placed in this region.

You can remove anything else from the page template what you don't need and replace this with static html.