I want to override the default html.html.twig according to my custom content-type. But I only get suggestions like:

* html--node--16.html.twig    
* html--node--%.html.twig    
* html--node.html.twig    
x html.html.twig 

I have tried for file-name


But this was not successful. Can anybody help?


You can use hook_theme_suggestions_HOOK_alter() to add another suggestion, something like:

function THEME_theme_suggestions_html_alter(&$suggestions, $variables) {
    // Check it's a node page.
    if (($node = \Drupal::routeMatch()->getParameter('node')) && $node instanceof \Drupal\node\NodeInterface) {
        // Insert as second to last so the more specific template by ID still works.
        array_splice($suggestions, count($suggestions) - 1, 0, 'html__node__' . $node->getType());

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.