Actually twig only suggest templates files name like this:
<!-- FILE NAME SUGGESTIONS:
* html--node--20.html.twig
* html--node--%.html.twig
* html--node.html.twig
x html.html.twig
-->
But I would have 2 kinds of template suggestion (like on my D6 website): One based on page + content type : page--CONTENT-TYPE.html.twig And other based on nodes + content-type : node--CONTENT-TYPE.html.twig or page--node-CONTENT-TYPE.html.twig
Actually I have a function in my .theme file like this but nothing change about suggestions:
function starterpf_d8_2019_theme_suggestions_page_alter(&$suggestions, $variables) {
$path = \Drupal::requestStack()->getCurrentRequest()->getPathInfo();
if ($path != '/') {
$path = trim($path, '/');
$arg = str_replace(["/", '-'], ['_', '_'], $path);
$suggestions[] = 'page__' . $arg;
}
}
Code found here
Thanks for help
EDIT: after exploring the output HTML, I get the page suggestions like this:
<!-- FILE NAME SUGGESTIONS:
x page--front.html.twig
* page--node.html.twig
* page.html.twig
-->
So, can I add different kind of suggestions with putting together part of your codes ? Like this:
function starterpf_d8_2019_theme_suggestions_page_alter(&$suggestions, $variables) {
$path = \Drupal::requestStack()->getCurrentRequest()->getPathInfo();
if ($path != '/') {
$path = trim($path, '/');
$arg = str_replace(["/", '-'], ['_', '_'], $path);
$suggestions[] = 'page__' . $arg;
}
#Suggestions pour les nodes
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
$suggestions[] = 'page__' . $node->bundle();
$suggestions[] = 'page__node_' . $node->bundle();
}
#Suggestions pour les types de contenus
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$content_type = $node->bundle();
$suggestions[] = 'page__'.$content_type;
}
}
And if I only want to create a file like node--CONTENT-TYPE.html.twig
instead of a page one ? Interesting in use of node--CONTENT-TYPE-nid.html.twig
too.
And what would be better to use ? Knowing that I include field datas inside template to theme easily them ?
In some use cases I will need to theme depending taxonomy term, is this native with D8 ?