I have a view which creates a block of comments. I have a comment.tpl.php in my theme folder which I use to theme the comments on the node.

To theme the view, I need a variant of comment.tpl.php and have tried the following:

comment-view.tpl.php comment-views.tpl.php comment-view--name-of-view.tpl.php comment-view-name-of-view.tpl.php

After cache clearing each option the template is still not picked up.

How can I theme this view please? By the way I am using the Omega theme.

  • what version of views are you running? have you explored Theme:Information that is available for each view? You are probably interested in the field content template file. just a guess there. – au_stan Mar 6 '13 at 13:05
  • Using views 3, the templates in theme:information do not contain the variables in comment.tpl.php. That is why i need to override comment.tpl.php – rix Mar 6 '13 at 13:08
  • any reason for voting this down or do you not really have a reason? – rix Mar 6 '13 at 13:22
  • I'm pretty sure there's no built-in support to override comment.tpl.php on a per-view basis (if it's not in theme:information then that's true). You'll need to implement the theme hook suggestions yourself – Clive Mar 6 '13 at 13:27
  • 1
    I don't have time to look into it too deeply right now, but basically you'll be implementing hook_preprocess_comment() at the theme/module layer, trying to find some sort of reference to the $view object inside the $vars array that's passed in, and adding something like: $vars['theme_hook_suggestions'][] = 'comment__' . str_replace('-', '_', $view->name);. After a cache flush the corresponding template file should work (e.g. comment--name-of-view.tpl.php) – Clive Mar 6 '13 at 13:46

Ok, I came up with some sort of solution, thanks to @clive.

function hook_preprocess_comment(&$vars){
    if (isset($vars['view'])) { 
        $view = $vars['view'];

            if ($view->name == "my_view_name"){
            $vars['theme_hook_suggestion'] = 'comment__' . str_replace('-', '_', $view->name);

I tried to do $vars['theme_hook_suggestions'][] but those templates were never picked up. Is it ok to directly set theme_hook_suggestion.

Really hope this helps someone else out there..

| improve this answer | |

When in the views UI, under 'advanced' on the right hand side, down the bottom you will see 'Theme' with a link next to it saying 'information' (under the 'Other' heading). Click the information link to see many template file name suggestions.

| improve this answer | |
  • As stated, I need to override comment.tpl.php as it contains the variables needed for theming. – rix Mar 6 '13 at 13:08

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.