I created a block view listing nodes of the content type: cars.

I added the block to the second sidebar.

After, I created 2 nodes of this type with the titles: car-1 and car-2.

Then the view block shows these 2 nodes. So far so good.

If I visit the page example.com/car-1 I see the block listing both the car 1 and car 2 nodes. I want to exclude the car-1 node from the block since I'm at: example.com/car1

This is what I did in the view:

1.  Click on add under "contextual filters".    
2.  Choose Content:nid.
3.  Under "when the filter variable is not available, choose "provide default value".
4.  From the drop down menu select "content id from url".
5.  Scroll all the way down to the bottom of the window and click on the
6.  "More" link.
7.  Click "Exclude"

I works fines if I visit a node, but the block is not shown in any Views (i.e.: in the frontpage view )

I know that the reason is that the Content nid is not present in a view, but don't know how to workaround this.


2 Answers 2


One option is to clone the block, make it show everything (remove the contextual filter and the exclude setting) and in block configuration (via admin/structure/block) configure it to show on all pages except node/*.

Another option, if you want to have everything in one display and don't mind using php, is to use Provide default value > PHP code:

if (arg(0) == 'node' && is_numeric(arg(1))) {
  return arg(1);
} else {
  return 0;

The exclude checkbox must be on.

So this is giving the sql the node id to be excluded, normally the current node id, and when there is no node id, the node id to be excluded is 0, in other words don't exclude anything as there is no nid 0.

Without checking that the second argument is numeric, this wouldn't work on the default front page as it would have 'node' but not have nid.


A use case for Page Manager / Panelizer. This is ment to be for this type op content page creation.

An other way is the context module. In that case you can define on which pages which context is used. Good example of this is in the julio distribution (www.drupal.org/project/julio)

If you are interested in the Page Manager way, watch this screencast http://nodeone.se/sv/node/702

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.