I have created an article listing view with a view mode "Teaser Full Width". The page looks fine and articles listed. When I tried to edit something using template_preprocess_node(&$variables)
, the hook is not working in Teaser Full Width. But the same work in the individual node when I click any article.
<?php
function templatename_preprocess_node(&$variables) {
kint($variables);die('test');
}
?>
I have already gone through different questions in StackOverflow.
if ($variables['view_mode'] == 'teaser_full_width'){ ... }
print_r
instead of kint
.max_allowed_packet
.templatename
is enabled and set as default.(Article Listing Page) Template file:- node--article--teaser-full-width.html.twig
template_preprocess_html
is working fine on this page.
template_preprocess_node
not working on this page.
(Article Single Page) Template file:- node--article--full.html.twig
Both hooks are working fine.
Does anyone know what the issue is? My drupal version is 8.6.10.
As per drupal's documentation template_preprocess_node() is the hook for node templates. Since the views listing page is containing the nodes but is not a node page so template_preprocess_node() is not working there. However, It is still an html page so template_preprocess_html() works there.
In simple terms, your "article listing view" is a page not node so template_preprocess_node() doesn't work.