Provide the $comments variable at the node template level so the comments can be manipulated within the node.tpl.php template.

CommentFileSizeAuthor
#2 comment_display.patch917 bytesentrigan

Comments

entrigan’s picture

I agree whole-heartedly. This is a fantastic module, and making the $comments variable available to all node templates would make it amazing. Also this, or something similar should be part of core.

entrigan’s picture

Component: Miscellaneous » Code
Status: Active » Needs review
StatusFileSize
new917 bytes

Ok I opened up the code and it is amazingly simple, so simple in fact, it might better be handled with some functions in your theme's template.php file. Anyway, I basically duplicated the page preprocess function as a new function comment_display_preprocess_node, which then makes the variable available to all node template files.

This is my first patch (simple as it may be) so please let me know if anything is awry.

sun’s picture

Status: Needs review » Needs work

I should probably commit the patch in #326342: Allow to output comments in a block to allow for this feature. Therefore, testing of the other issue would be appreciated.

sn0rcha’s picture

I can't get that to work in a zen sub theme some reason.

Any ideas?

valderama’s picture

hi!

did you manage to make it work in a zen-subtheme so far?

greets,
walter

valderama’s picture

it works for me now... in the end i just put the preprocess function in the template and replaced the "phptemplate" prefix with the name of my theme ("eca"):

function eca_preprocess_node(&$vars) {
$vars['comments'] = '';
if (function_exists('comment_render') && !empty($vars['node']) && $vars['node']->comment) {
$arg2 = arg(2);
$vars['comments'] .= comment_render($vars['node'], ($arg2 && is_numeric($arg2) ? $arg2 : NULL));
}
}

____

in the node template you then have the $comment variable. i also had to print out the $links variable by hand, to get the "login or register to post comments" link, when there is no comment there already:

          print $comments;
         
          if(empty($comments))
            print $links;     

hth,
walter

jafar104’s picture

Valderama's comments worked like a charm, just changed the theme's name to my theme's name and inserted that into template.php, then added the variable $comments to my node.tpl.php file.

Thanks!

jrao’s picture

Actually you can just call comment_display_preprocess_page in your template_preprocess_node, instead of copying the code inside that function.

sun’s picture

This patch needs to be re-rolled due to #326342: Allow to output comments in a block

haysuess’s picture

I couldn't get this to work. I put this in my template file:

function acquia_prosper_preprocess_node(&$vars) {
$vars['comments'] = '';
if (function_exists('comment_render') && !empty($vars['node']) && $vars['node']->comment) {
$arg2 = arg(2);
$vars['comments'] .= comment_render($vars['node'], ($arg2 && is_numeric($arg2) ? $arg2 : NULL));
}
}

And this in my node.tpl.php:

<?php
          print $comments;
        
          if(empty($comments))
            print $links;    
?>

It didn't work.

I have the plugin working fine, but my comment form is also being displayed on the node edit page, which is obviously undesirable.

haysuess’s picture

No offense, but CommentBlock is a much better module. It uses Views and is much easier,, more flexible, and doesn't require changing of page.tpl.php or node.tpl.php. You might want to link to it from the front page of this module.

Here it is: http://drupal.org/project/commentblock

entrigan’s picture

@#11,

I would not say your statement was offensive, but I do think it is rude, and at the least unwarranted. CommentBlock and Comment Display take a very different approach to the same problem. Comment Display I would guess based on it's approach is faster, while CommentBlock gives non-coding admin's control over the display.

Different, not better.

haysuess’s picture

Sorry if it was rude, but it is much more flexible, and easier, and since it is views/block based can be customized much more.

entrigan’s picture

Fair enough, and thanks for the link. I had not known about that project.