Search code examples
drupaldrupal-9

HOOK_module_theme_suggestions_node_alter suggestion twig not working


I implemented a HOOK_module_theme_suggestions_node_alter to add a custom twig template. Now below is my code

function gf_theme_module_theme_suggestions_node_alter(array &$suggestions, array $variables) {
    $suggestions[] = 'node--products-template--simple';
  
}

Now it does appear in the inspector but the page does not use the custom twig file I added eventhough the file exist. Any idea?

Below are the screenshot

enter image description here

enter image description here

I already cleared my cache but still no luck. It's still loading the node.html.twig eventhough the node--products-template--simple.html.twig exist. The file exist in the same folder as the node.html.twig file


Solution

  • Use underscores instead of hyphens in suggestions:

    $suggestions[] = 'node__products_template__simple';