I need to create a node twig template that is just for the basic page
content type that based on a custom field on the content type. We have other content type like Article
, Blog
, Products
that do not need these specific twig template.
How would we create twig templates based on the field_type
so that it only applies to the basic page content type?
Here is what we tried, but couldn't find how we could detect for the basic page
content type and the value for the field_type
. We tried ksm($suggestions)
and ksm($variables)
, but it does not print which implies that the hook isn't called even after clearing cache.
function mymodule_theme_suggestions_node_alter(array &$suggestions, array $variables) {
// This is what we are looking for.
$node_bundle = $node->bundle();
if($node_bundle == 'page') {
// we want something like this.
$node_type_value = $node->field_type->value;
$node_view_mode = $node->view_mode; // not sure what this would be.
$suggestions[] = 'node__' . $node_bundle . '__' . $node_type_value
}
}
$node
(if you haven’t, it’s in$variables[‘node’]
)