0

In a module I have created a custom link by creating a custom route inside the mymodule.routing.file.yml and the mymodule.links.menu.yml file. In my theme.theme file I have defined a hook_page_alter to add a template suggestion. With the debug mode and in the html code of the custom page, I see the proposed template suggestions.

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'page' -->
<!-- FILE NAME SUGGESTIONS:
* page--mycustomtemplate.html.twig
x page.html.twig

I have build a new template with this name 'page--mycustomtemplate.html.twig'. After clearing the cache, the new template isn't called, and the default page template is always actived.

Did I forget something?

1
  • Where you placed the template?
    – leymannx
    Jul 29, 2019 at 17:42

1 Answer 1

0

I'm guessing you put the template in your module folder and not in a theme?

You need to register the template with something like this in your .module file:

/**
 * Implements hook_theme().
 */
function mymodule_theme() {
  $theme['page__mycustomtemplate'] = [
    'template' => 'page--mycustomtemplate',
  ];

    return $theme;
}
2
  • Hi Leigh ! I tried to use your code in my custom module without success. The template is placed in the theme and in the module templates directory... Also I add ''base hook' => 'page' in your code without success...
    – user28220
    Feb 26, 2019 at 20:34
  • In my controler, if I add this line : '#theme' => 'page__mycustomtemplate', the template is called from my theme directory. It's a possible solution for the moment. But, in the debug html code, the default page.html.tpl is always mentionned and my custom template don't appears in the template suggestions...
    – user28220
    Feb 27, 2019 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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