I've creating an intranet module for Drupal 8 and I want to use a custom theme for it, like an admin theme(with page/node/field templates) where I can map region like menu, header, footer... but only for my module.

I didn't find any specific doc about this.

Thanks for your help!


Another option would require creating a theme (in addition to your module). Then have your module indicate it uses that theme. Here is a nice article on how to do this https://speedandfunction.com/switching-themes-programmatically-drupal-8/

In this scenario, you would have your main theme and the theme used by your module. You could indicate that the theme used by your module was a sub-theme (https://www.drupal.org/docs/8/theming-drupal-8/creating-a-drupal-8-sub-theme-or-sub-theme-of-sub-theme) of your main theme which could reduce some theme coding management.

| improve this answer | |
  • I found an article like yours for my needs here : annakalata.com/blog/… I just replace the active menu by my route name. I think I explain it much better. – Leeroy May 23 '17 at 14:22

You cannot specify region on your module, but you can custom your page or your block.

Regions are specify into main theme.

First, you need to create a folder on your module root directory :


Inside, you ll put all your custom template.

For example :



Then you need to declare all your templates :

In myModule.module :

 * Implements hook_theme().
function myModule_theme() {
  return [
    'page1' => [
      'template' => 'test',
      'render element' => 'children',

      'page2' => [
          'template' => 'page2',       
          'render element' => 'form',

And after, in your controller or your form :

return $build +  [
  '#test'=>"its content for my variable inside my template",
| improve this answer | |
  • Yeah thanks, but that's what I do for now and I don't like this way, that make no sense to include every part of the module ( header, footer, menu, aside) on every page it should be the opposite. I hope someone could find a solution. – Leeroy May 22 '17 at 14:31

If u want custom theme for module u just need to use template suggestions, output content from php and then render it in twig files.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.