0

I've read documentation about name suggestions but I don't get it. My goal is to create a specific template used only with a specific content type (Drupal 8).

I've copied page.html.twig to edit the code inside a new file, named page--recette.html.twig (recette is the name of my content type) but this doesn't work.

html--node--recette.html.twig doesn't work neither.

Link : http://ofhjfqaj.preview.infomaniak.website/cms/recette-sans-gluten/tarte-tatin-comme-la-vraie

1 Answer 1

4

You can provide node level content type templates with the pattern node--node_type.html.twig.

So, for an article it would be node--article.html.twig.

In your case, it would be node--recette.html.twig. You can also provide view mode level twigs the same way, with node--node_type--view_mode.html.twig files.

Lets say you wanted to customize the teaser display markup:

node--recette--teaser.html.twig

If you enable twig debugging, you can see in your HTML source (comments) which template is being used, and what other template pattern names are available to you:

https://www.drupal.org/docs/8/theming/twig/debugging-twig-templates

Going any further than that, you would need to implement hook_theme_suggestions_alter to get more custom template names based on some sort of logic.

7
  • Do I need to rewrite all the page in this file ? pastebin.com/XaXKn4sr here is the content of my node--recette.html.twig and it doesn't print anything ;( Sorry, i'm really novice with twig.
    – Tourist
    Commented Mar 29, 2017 at 14:32
  • 1
    No, the node level template only handles the content of a node. page level template controls output of of regions/markup in the theme.
    – Kevin
    Commented Mar 29, 2017 at 14:33
  • Node template variables can be output with {{ content.field_name }} - content is the render array. page. would do nothing in the context of a node twig template.
    – Kevin
    Commented Mar 29, 2017 at 14:34
  • Note: {{ content.field_name }} refers to fields on the node type.
    – Kevin
    Commented Mar 29, 2017 at 14:40
  • I really don't get the logic behing it :( I'm using Views to create blocks for each field. In /structure/block, I place blocks (created with Views) in the regions I want. How do I print the regions with my node--recette.html.twig ?
    – Tourist
    Commented Mar 29, 2017 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.