I want to add a comment form to my view by using the following code:

print drupal_get_form('comment_node_project_form', array('nid' => $node->nid), 'comment');

However, it shows up a error saying that the variable $node->nid is undefined. I then realized it is a view, not a node.

In the view, by choosing the right URL, e.g. /projects/{username}/{nodeid}, I only show one content.

I guess I can get the node ID by parsing the 3rd argument of the URL. How do I get the node ID from the view's URL?

1 Answer 1


If the view uses fields, you can add a field labeled Content: Nid - and either build the link in the template by yourself or try to Rewrite the field in the Views admin UI. If the View uses display views, such as Teaser, you should be able to use the $node variable in the teaser (in this case) tpl file.

  • I add a field labeled content:nid in the view, but nothing happens.
    – helxsz
    May 13, 2012 at 13:09
  • Wait, now that the question has been re-edited I kinda get a better understanding that it's not the individual nodes that you want to allow comments for, but the entire view. Is that correct? May 13, 2012 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.