How can i theming the comments like this in the node.tpl.php (with a new column after 3 comments)? I want to use this:

$cols = array();

$cols[] = '<div class="headline">' . t(`Kommentare`) . '</div>';

$comments = comment_render($node, $node->cid);
$comcolnum = 0;

foreach($node-cid as $comcol){
$cols[] = '<div class=description-' . $comcolnum . '">' . $comcol['view'] . '</div>';

$cols[] = '<div class="comment-form">' . drupal_get_form('comment_form',array('nid' =>  
$node->nid)) . '</div>';

print theme_table(array(), array($cols))

$node->comments, &comments or ... doesn`t work. I think first i need to override the comment output in the template.php like this for Drupal 6:

function phptemplate_preprocess_node(&$vars) {
$vars['node']->comment = 0;
$vars['comments'] = $vars['comment_form'] = '';
if (module_exists('comment') && isset($vars['node'])) {
$vars['comments'] = comment_render($vars['node'], $vars['node']->cid);
$vars['comment_form'] = drupal_get_form('comment_form', array('nid' => 

But! What i need to get every comment for the foreach function? I`m really new with PHP and Drupal API, but i want to learn it! Can someone show me the right way?

Greeting Bruno


Use MYTHEME_preprocess_node($vars) instead of MYTHEME_preprocess_page($vars) to get your declared variables in template.php to get in node.tpl.php.

I see you are already using template_preprocess_node(), so just put all those things which are intended for node.tpl.php in that function.

| improve this answer | |
  • i get everytime the same errormessage: warning: Invalid argument supplied for foreach() The script for the formfield works perfect: $cols[] = '<div class="comment-fomr">' . drupal_get_form('comment_form',array('nid' => $node->nid)) . '</div>'; – Bruno Jul 4 '13 at 20:30
  • @Bruno What is output of $node->comments ? – RajeevK Jul 5 '13 at 11:00
  • <?php print $comments ?> give me all the commenst of the node, but i dont know how i can use it for foreach(). I customised the code now in node.tpl.php to: $comments = comment_render($node, $node->cid); $comcolnum = 0; foreach($node-cid as $comcol){ $comcolnum++; $cols[] = '<div class=description-' . $comcolnum . '">' . $comcol['view'] . '</div>'; } $cols[] = '<div class="comment-form">' . drupal_get_form('comment_form',array('nid' => $node->nid)) . '</div>'; – Bruno Jul 5 '13 at 11:09
  • @Bruno As I see, you want to theme comments at your node. Why don't your check comment.tpl.php, which get call to generate all the comments at your node. You can override it for particular content type like comment--node-[TYPE_NAME].tpl.php. You can put some more classes/id for each elements & then apply design.. You will find default comment.tpl.php in the $base_url/module/comment folder. Copy that & paste in your theme folder to go further with it.. – RajeevK Jul 5 '13 at 11:15
  • Ok, this can be an simpler solution. – Bruno Jul 5 '13 at 11:26

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.