Use different comment template for replies-to-top-comment I tried to make StackExchange-like comment section with different template for the comment replies. I create two template for both top-level comment and its replies. This is the result of the two comment.tpl.php file rendered and then collated in GIMP.



This is comment.tpl.php used for top comment contained in cyan box.

&lt;div class="user-comment"&gt;
  &lt;div&lt;?php print $attributes; ?&gt;&gt;
    &lt;div class="user-identification"&gt;
      &lt;?
        print render($avatar) . "&lt;br/&gt;";
        print $commenter_name . "&lt;br/&gt;";
        print $creation_date;
      ?&gt;
    &lt;/div&gt;
    &lt;?php
      hide($content['links']);
      print render($content['comment_body']);
      print render($content['links']);
    ?&gt;
  &lt;/div&gt;
&lt;/div&gt;


While this is comment.tpl.php used for comment reply contained in yellow box.

&lt;div class="user-comment"&gt;
  &lt;div&lt;?php print $attributes; ?&gt;&gt;
  &lt;?php
    print render($content['comment_body']);
    print " - " . $commenter_name;
    print render($content['links']);
   ?&gt;
  &lt;/div&gt;
&lt;/div&gt;


If i use one of these template, it will effect ALL the comments as shown below.



I know I can change the style rudimentarily via theme css as suggested in this question, but going by this route means that I have to create one-size-fit-all template for both case that won't be pretty.

My question is: Is there any template file I missed or any other strategy that I can employ to make separate template that will target only the replies-to-top-comment?
I manage to solve this problem by exploiting the pid (parent ID) value in the $comment variable. First, I check if the corresponding comment is a top-level comment. It is a top level comment if the pid value is 0. The code inside comment.tpl.php so far is:

if ($comment-&gt;pid == 0) {
  // Top level comments code here
} else {
  // Replies to comments code here
}


The code above will split the template programatically already, but it will be better if I worked at two separate files for the two cases. To do this, I used drupal_get_path function to point every case inside comment.tpl.php to their corresponding template.

In my case, I create these two templates inside my theme folder:


/templates/comment/comment-top.tpl.php for the top comment
/templates/comment/comment-reply.tpl.php for the replies


The code inside comment.tpl.php then become:

if ($comment-&gt;pid == 0) {
  include drupal_get_path('theme', 'mytheme') .
    '/templates/comment/comment-top.tpl.php';
} else {
  include drupal_get_path('theme', 'mytheme') .
    '/templates/comment/comment-reply.tpl.php';
}


Of course change the mytheme in the code to your theme name.

To finish off, I pasted the template I posted above in the question to the corresponding template. It will render the template properly with all the variables you define inside the preprocesses function working.