6

I'm trying to add a custom template file per content type for my comments. comment--[contenttype].tpl.php is not being picked up by default. I read where this may be a d7 bug or perhaps by design. Then I also read that I can add a preprocess function to my template.php, but I'm still a bit confused. I've added this to my theme;

function bartik_preprocess_comment(&$variables) {

}

but what additionally do I have to add to this function to get it to pick up the suggestions. If someone could give me the exact code for my example it would be much appreciated, assuming that my content type is called car.

7

According to Drupal 7 Template Suggestions, the custom comment template for a content type should be named comment--[node-type].tpl.php. That is confusing, because the actual template you have to use for an article content type is comment--node-article.tpl.php.

Alternatively you could add your custom template suggestion inside template.php:

function bartik_preprocess_comment(&variables) {
  // Let's say you want to have a custom template like comment--custom-TYPE.tpl.php
  // e.g. for an article content type, the template file will be comment--custom-article.tpl.php
  $variables['theme_hook_suggestion'][] = 'comment__custom_' . $variables['node']->type;
}
  • 1
    ah, I think that is the issue I missed that node-type actually mean the word node and then the node type, indeed that is confusing – user379468 Jan 9 '12 at 0:48
  • That's what i missed either :) – Alexander Kim Sep 17 '13 at 16:33
0

You can copy the file comment.tpl.php form comment module folder and rename it to comment--node-content_type_name.tpl.php

  • Hello. You forgot the node type part in file name. – Mołot Feb 28 '14 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.