Normally you'd simply use node.html.twig
and then have different node templates for other node types. But I can imagine that it can make sense to bundle certain node types differently instead of providing distinctive templates for all other node types.
So you can implement hook_theme_suggestions_alter
or hook_theme_suggestions_HOOK_alter
to provide an extra template suggestion. The following snippet lets nodes of a given type pick up a node--foobar.html.twig
template if present.
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function MYTHEME_theme_suggestions_node_alter(array &$suggestions, array $variables) {
$bundles = [
'contenttype1',
'contenttype2',
'contenttype3',
'contenttype4',
'contenttype5',
];
/** @var \Drupal\node\Entity\Node $node */
$node = $variables['elements']['#node'];
if (in_array($node->bundle(), $bundles)) {
$suggestions[] = 'node__foobar';
$suggestions[] = 'node__foobar__' . $variables['elements']['#view_mode'];
}
}
node.html.twig