Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anybody know how to get the nid from a node using contextual filters or filter criteria in views

WITHOUT using "Get id from url"? I was thinking about using PHP or getting it from a node-field.

My view is a block of comments that is to be placed together with a node. The comments needs to belong to the node and linked by node ID. In this case the "Get ID from url" wont work since the node itself is listed in another view.

It is a view-block (containing comments) inside of a node that is listed in a view.

share|improve this question
up vote 1 down vote accepted

If you are loading and displaying your view in the node.tpl or node--<content-type>.tpl file, you could supply the current node nid as an argument to your block view, then you can setup a contextual filter for Content: Nid. I would do something like this:

// get view
$view = views_get_view('YOUR_VIEW_NAME');
// set display for view
// set current node nid as argument to view
// execute view
// render view
print $view->render();
share|improve this answer
Since I already posted a working solution on stackoverflow I thought it would be a nice to do the same here=) – Cyclone Nov 24 '12 at 5:18
Awesome. thanks for this – Dushyant Joshi Aug 25 '14 at 12:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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