0

Following this answer, I'm trying to override core/themes/seven/templates/node-add-list.html.twig using hook_theme_suggestions_HOOK.

So, I added the following function in modules/custom/domain_filter/domain_filter.module

function domain_filter_theme_suggestions_node_add_list(array $variables) {
  $suggestions = [];
  $suggestions[] = 'node_add_list__' . 'custom';
  return $suggestions;
}

I created the custom twig file in my module: modules/custom/domain_filter/templates/node-add-list--custom.html.twig

The suggestion appear well in theme debug but it's not applied (the x is in front of node-add-list.html.twig):

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'node_add_list' -->
<!-- FILE NAME SUGGESTIONS:
   * node-add-list--custom.html.twig
   x node-add-list.html.twig
-->

How to apply node-add-list--custom.html.twig?

2

Finally I found a paragraph in the documentation. When using modules, we need to register the template using HOOK_theme(). So, I added the following function in modules/custom/domain_filter/domain_filter.module

/**
 * Implements hook_theme().
 */
function domain_filter_theme() {
  return [
    'node_add_list__custom' => [
      'base hook' => 'node_add_list',
    ],
  ];
}

Then my custom template modules/custom/domain_filter/templates/node-add-list--custom.html.twig is now applied.

| improve this answer | |
1

you need add to your theme

themes/yourtheme/templates/node-add-list--custom.html.twig
| improve this answer | |
  • Thanks, this can be useful when you create a subtheme or a new theme but I just want to use a module. – Kwadz Sep 13 '18 at 9:39

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.