What the proper method of outputting a page from your module without any additional theming beyond your template, for example to make a page that is good for printing?
I've tried a few different methods based on Drupal 7 versions. The only one to work being to render the build array and the kill further PHP loading, however this doesn't feel right. In Drupal 7, I could set up a 'delivery callback' in the hook_menu() - but I can't seem to figure out how to replicate that behaviour now.
my_module.routing.yml:
my_module.user_timesheets:
path: '/my_module/timesheets/{weekOf}/{uid}'
defaults:
_controller: '\Drupal\my_module\Controller\MyModuleAdminController::timesheets'
_title: 'My Module Timesheets'
requirements:
_permission: 'admin'
my_module.module:
$theme['timesheets'] = [
'render element' => 'build',
'template' => 'timesheets',
];
MyModuleAdminController.timesheets:
public function timesheets($weekOf, $uid = null) {
$build['#theme'] = 'timesheets';
...code building values...
$build['#staff'] = $staff;
$build['#title'] = 'Timesheets - ' . $weekOf . ' to ' . $this->dateService->getWeekStartDate($weekOf);
$build['#attached']['library'][] = 'my_module/timesheets';
//print render($build);
//die();
return $build;
}
my_module.libraries.yml:
timesheets:
css:
theme:
lib/timesheets.css: {}
Edit: To over-ride something like page.html.twig in your module, you make a template called page--my_module--html.twig and then declare it in your modules my_module_theme() function.
/**
* Implements hook_theme().
*/
function my_module_theme() {
$theme['page__my_module__timesheets'] = [
'template' => 'page--my_module--timesheets',
];
return $theme;
}