HI there,

I apologise if this isnt a bug and its just my understanding thats incorrect but im trying to add comment template files to override based on node type, now the documentation here:


States that:


will work (it also contradicts itself and states that "a comment made on an article-type node would be "comment--node-article.tpl.php"...this is wrong surely..)

So anyway ive got a content type of "question" and have tried:


Ive put it in the same folder as the base comment.tpl.php (in the theme) as well just to be sure its not the fact that I had it in its own folder in the theme. This just doesnt work, it seems only the comment.tpl.php in my theme is ever used.

Anyway while trying to figure out why this wasnt working I noticed that the template_files section of code in $variables is not in the D7 version of preprocess_comment.

Can anyone point me in the right direction on this is supposed to work or confirm this is a bug??


mikeskull’s picture

Oops sorry this is for 7.10 not 7.9

mikeskull’s picture

Version:7.9» 7.10
joachim’s picture

Title:Cannot theme comment by node type» [regression] Cannot theme comment by node type
Version:7.10» 8.x-dev

When I output all the variables available in comment.tpl theme_hook_suggestions is not set, which seems to confirm the bug.

Furthermore, template_preprocess_comment() seems to have no suggestions in D7 or D8, whereas it did in D6. (And compare with template_preprocess_node(), which does).

ovi.indrei’s picture

I don't think there is a bug, but rather some misleading information on Drupal 7 Template Suggestions, which should be corrected. If you look at comment_view function, you'll get to see

$build += array(
    '#theme' => 'comment__node_' . $node->type,
    '#comment' => $comment,
    '#node' => $node,
    '#view_mode' => $view_mode,
    '#language' => $langcode,

From my understanding, if you want to customize the comments on a content type named "question", you will have to use a template named comment--node-question.tpl.php.

@mikeskull, can you confirm you tried this template, flushed caches and still didn't work? I am asking this, because in your initial post you wrote you tested "comment--node-question.php" and I'm not sure if it's a typo or not, but it's missing the ".tpl".

mikeskull’s picture

Apologies been away from work for a while and remembered I had this up.

ok so just tried:


for a node type of advice_article (machine name)

put this template next the main comment.tpl.php in my theme chucked some text in the node based one and it DOES NOT show on the screen, refreshed all caches (memcache, drush cc all, admin flush all caches) still no go.

Can someone else prove this is not just me?

isuk’s picture

Version:8.x-dev» 7.12

Hi Guys

Based on some work I was doing for creating custom page.tpl.php. I have used

function themename_preprocess_comment(&$variables) {
  $variables['theme_hook_suggestions'][] = 'comment__' . $variables['node']->type;

This has allowed me to create templates like

comment--<content type>.tpl.php

If someone could confirm I'm not mad, would be appreciated.


osopolar’s picture

Status:Active» Closed (cannot reproduce)

For me #4 is working well out of the box (with omega theme), without any additions to themename_preprocess_comment().

Tested with: comment--node-question.tpl.php (+ cache clear).

@mikeskull: Does it work for you now? Please check with a content-type named "question".