I am making a template in Drupal 8. At this moment, I made a theme in the /themes directory; there, I have my .theme file and a copy of the html.html.twig file from the core/themes/stable directory.

I have enabled Twig debugging mode and in the Chrome inspect tool I read the following.

   * html--front.html.twig
   * html--.html.twig
   x html.html.twig

I added the following hook to the theme file.

function testTheme_suggestions_html_alter(array &$suggestions, array $variables) {
    $suggestions[] = 'html__testHTML';

After clearing the cache, there isn't any change to the file name suggestions.

Also I have activated kint() in html.html.twig file that is located in my theme root, but kint() also shows only these variables.

'theme_hook_suggestions' => array(2)
string(6) "html__"
string(11) "html__front"

Why doesn't the new suggestions appear?

  • Is this code even being hit? – Kevin Mar 7 '17 at 14:13
  • well, this code resided in .theme file, i think yes it must be executed when site is loaded... (I in preprocess hook to be sure that that preprocess hook is executed i put in it [ echo '<script>'; echo 'alert(" ")'; echo '</script>';], this way i can be sure that i am entering in preprocess hook. i have tried to do so in suggestions_html_alter but there nothing happens ) – George Chanturia Mar 7 '17 at 14:23
  • You need to know if it is being hit by using a debugger or exit. If you clear cache and it still isn't being hit, then you can start there. – Kevin Mar 7 '17 at 14:24
  • That was a hint. – Kevin Mar 7 '17 at 14:47

Try it like this:

function yourthemename_theme_suggestions_html_alter(array &$suggestions, array $variables) {
  $suggestions[] = 'html__testHTML';

Replace "yourthemename" with your theme name.

| improve this answer | |
  • Thank you so much!!!! this works!!! now i see my mistake i thought that hook_theme mus be reappraised with my theme name, but only hook must be reappraise i this case!!!! (I was looking for solution more than 4 hours!!!!) – George Chanturia Mar 7 '17 at 14:52

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.