How to print "node title" in comment.html.twig template? i am styling my comments in comment.html.twig template and need to show &quot;node title&quot; of the node to which the comments belong.
I've tried a number of options, and the only one that works relatively is below:
function enar_preprocess_comment(&amp;$variables){
   $node = \Drupal::request()-&gt;attributes-&gt;get('node');
   $variables['nodetitle'] = $node-&gt;getTitle();
}

However, if I click &quot;reply&quot; in the comments, I get this error.
Error: Call to a member function getTitle() on null in mytheme_preprocess_comment() 

My question is, how to print &quot;node title&quot; in comment.html.twig template?
Because the comment reply page/route does not belong to a Node entity
$node = \Drupal::request()-&gt;attributes-&gt;get('node'); 

returns null.
Instead, access the node object with
$node = $variables['commented_entity'];