I created a view to generate a page which contains the comments appended to a particular node, on the views-view-row-comment.tpl.php file it states:

* Rather than doing anything with this particular template, it is more
* efficient to use a variant of the comment.tpl.php based upon the view,
* which will be named comment-view-VIEWNAME.tpl.php. This isn't actually
* a views template, which is why it's not used here, but is a template
* 'suggestion' given to the comment template,

This suggestion is not being generated, investigating in the module code, the template suggestions for nodes is being generated on the views.module

specifically here

function views_preprocess_node(&$vars) {
  // The 'view' attribute of the node is added in template_preprocess_views_view_row_node()
  if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) {
    $vars['template_files'][] = 'node-view-' . $vars['node']->view->name;
    if(!empty($vars['node']->view->current_display)) {
      $vars['template_files'][] = 'node-view-' . $vars['node']->view->name . '-'. $vars['node']->view->current_display;
    }
  }
}

however no similar function exists for comments...

Can anyone suggest a workaround?

Comments

merlinofchaos’s picture

Status: Active » Fixed

Good point. Documented that way but never actually happened. Fixed in CVS. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

sultancillo’s picture

Version: 6.x-2.0-rc5 » 6.x-2.1

This is still an issue the problem is here:

/**
 * Template helper for theme_views_view_row_comment
 */
function template_preprocess_views_view_row_comment(&$vars) {
  $options = $vars['options'];
  $view = &$vars['view'];
  $plugin = &$view->style_plugin->row_plugin;
  $comment = $plugin->comments[$vars['row']->cid];
  $node = node_load($comment->nid);
  // Put the view on the node so we can retrieve it in the preprocess.
  $node->view = &$view;

  $links = '';
  if (!empty($options['links'])) {
    $links = module_invoke_all('link', 'comment', $comment, 0);
    drupal_alter('link', $links, $node);
  }

  $vars['comment'] = theme('comment_view', $comment, $node, $links);
}

this:

  // Put the view on the node so we can retrieve it in the preprocess.
  $node->view = &$view;

should be:

  // Put the view on the COMMENT so we can retrieve it in the preprocess.
  $comment->view = &$view;
sultancillo’s picture

Status: Closed (fixed) » Active

Reopened issue with above comment

merlinofchaos’s picture

I believe the node is always available in all the comment templates, so I don't think there is a real need to put the view on the comment. Also, the comment can be an array I think, which makes it a little less safe to put random data on it.

sultancillo’s picture

OK my bad... here's the situation, i had some code on my template.php to go around this... I removed it and installed the original module

Still the template suggestions are not being generated...

Here's the problem...

/**
 * A theme preprocess function to automatically allow view-based node
 * templates if called from a view.
 */
function views_preprocess_comment_view(&$vars) {
  // The 'view' attribute of the node is added in template_preprocess_views_view_row_comment()
  if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) {
    $vars['view'] = &$vars['node']->view;
    $vars['template_files'][] = 'comment-view-' . $vars['node']->view->name;
    if(!empty($vars['node']->view->current_display)) {
      $vars['template_files'][] = 'comment-view-' . $vars['node']->view->name . '-'. $vars['node']->view->current_display;
    }
  }
}

Should be:

/**
 * A theme preprocess function to automatically allow view-based node
 * templates if called from a view.
 */
function views_preprocess_comment(&$vars) {
  // The 'view' attribute of the node is added in template_preprocess_views_view_row_comment()
  if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) {
    $vars['view'] = &$vars['node']->view;
    $vars['template_files'][] = 'comment-view-' . $vars['node']->view->name;
    if(!empty($vars['node']->view->current_display)) {
      $vars['template_files'][] = 'comment-view-' . $vars['node']->view->name . '-'. $vars['node']->view->current_display;
    }
  }
}

(note the function name)

otherwise this function is never executed and the view object is never attached to the node...

merlinofchaos’s picture

Status: Active » Fixed

Alright, changed in -dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.