Score:-1

How do I suggest to use a template name like "node--[content-type-name]"?

us flag
jfc

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?

Kevin avatar
in flag
This pertains to the HTML template itself (outermost wrapping template), not the node template. Those suggestions are further down in the source.
apaderno avatar
us flag
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*.
Score:-1
de flag

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).

Kevin avatar
in flag
That is still the page level template. Node templates begin with node, like node--article.html.twig.
misterdidi avatar
de flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.