Friday, September 16, 2011

How to identify if a comment is a reply to a parent comment in Drupal ?

It is pretty simple, but didn't find it listed anywhere,

if($comment->pid ! =0 )
{

//This is a reply to a comment
}

This will come in handy if you want to format a comment reply differently from a parent comment. eg - I had to hide the subject lines in comment replies to avoid too much chatter on the page. However the parent comment was still to have a subject line and hence I could not use the Drupal setting of disabling 'Subject on Comment' under the comment settings.


I now do capture the auto comment titles generated by Drupal on the comment replies but do not show them as in most of the cases, it is redundant with the comment reply.

Hope this will help developers looking for it and save some time !

0 comments: