-1

I would like to name my node template after the content type title, but my suggestions only show the node number.

FILE NAME SUGGESTIONS:

  • html--node--1.html.twig
  • html--node--%.html.twig
  • html--node.html.twig
  • x html.html.twig

I don't want to name it node--1 just in case the node ID changes in the future. I'd like to name it node--content-type-name.

Is there a setting to enable this?

2
  • 3
    This pertains to the HTML template itself (outermost wrapping template), not the node template. Those suggestions are further down in the source.
    – Kevin
    Sep 28 '21 at 20:01
  • The question is not clear: It talks of node templates, but it shows suggestions for the HTML template, which is different from a node template. For the node templates, the Node module already suggests node--[content-type].html.twig.
    – apaderno
    Sep 29 '21 at 10:44
-1

Just to be sure, do you want to name your node template (node.html.twig) or your html template (html.html.twig) after your content type name?

In the first case, the node type name template suggestion is accessible out of the box on the node template level. You just need to dig a bit further down into your html to where you are displaying the node (usually in the Main content block) to see the list of template suggestions.

In the event of the html template, since it is the top-level template and its {{content}} may contain anything (nodes, taxonomy terms, blocks...) you will have to rely on theme hook suggestions to build your own template name suggestions and tell Drupal about it. In that case, you have to use hook_theme_suggestions_html_alter() (See documentation about this hook).

2
  • 1
    That is still the page level template. Node templates begin with node, like node--article.html.twig.
    – Kevin
    Sep 28 '21 at 21:17
  • Ok, then @Kevin is right, it is node level templates you are interested into, not page level nor html level. You need to browse a little deeper into your HTML to find the output of your node (usually in main system block which has CSS class block-system-main-block) and the template suggestions given by Twig debug.
    – misterdidi
    Sep 29 '21 at 6:20

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.