I have created a view in a block, to display some related information to the current content type being displayed into the block. More precisely, I want to display the block only for book pages.

What I did is to add a contextual filter based on content type. For "WHEN THE FILTER VALUE IS NOT AVAILABLE", I provide a default value for "PHP contextual filter code" as follows

$node = node_load(arg(1));
return $node->type;

For "WHEN THE FILTER VALUE IS AVAILABLE", I use "Specify validation criteria" for content types with "book page".

I tried this but it didn't work. I think because I am using aliases in the url, it does not work.

What am I missing?

P.S: My final goal is actually to extract the group audience from the current book page and display the admins of that group into the block.

2 Answers 2


In your case you don't need to provide any default value with PHP code.

Remove your contextual filter and add new one: Content: nid.


Provide default value -> content ID from URL

"When the filter value IS available or a default is provided"

Specify validation criteria

Validator -> Content -> book


Why are you checking the content type with the view?

If I understood your question, you want to display the view's block only on certain content type ('Book'). A much easier solution will be:

  1. Go to Dashboard >> Structure >> Blocks
  2. Find the view's block and go to its configuration
  3. Under the 'Content Types' tab add 'Book'

That is it!

Block configuration page

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.