Saturday, February 12, 2011

How to print comment anywhere in Drupal

Drupals standard practice of printing node comments below the node can get a bit stale. Sometimes you may want, or simply need to, print them somewhere else. Wouldn’t be great if comments and the comment form were just variables you could move around?

Well you can—thanks to Drupal 6’s phptemplate_preprocess_page function we can easily store both the comments and the comment form in variables. The only caveat is that you must set the comment reply form to a separate page first, or something might break.

The following snippets store the comment form and comments in variables and allow you print them in page.tpl.php.


// Store comments and the comment form in variables
function phptemplate_preprocess_page(&$vars) {
  $vars['comments'] = $vars['comment_form'] = '';
  if (module_exists('comment') && isset($vars['node'])) {
    $vars['comments'] = comment_render($vars['node']);
    $vars['comment_form'] = drupal_get_form('comment_form',
    array('nid' => $vars['node']->nid));
}
}

// Unset comments from node
function phptemplate_preprocess_node(&$vars) {
$vars['node']->comment = 0;
}
?>



Now you can print $comments and $comment_form anywhere in page.tpl.php, and they will only print when you are viewing a node.

Saturday, February 5, 2011

Drupal Essential Training

Here is a source for a small video tutorial to start drupal development. This concised video includes basic training and ideas for drupal website development. If you have a high speed internet connectivity, you can grab these tutorial within 1 Hour, it is 512MB in size. This video is actually from lynda.com who are specialized in selling good video tutorial for web development. There might be some copyright issue in this video, so it can be removed from rapidshare. Hurry, before the links expire.

http://rapidshare.com/files/155384178/LC-DET.part1.rar
http://rapidshare.com/files/155384140/LC-DET.part2.rar
http://rapidshare.com/files/155384017/LC-DET.part3.rar

Let me know your comments also.

Here is the preview of the tutorial from youtube.