0

I have been going around in circles with this for a few hours now... Time to ask for help!!

I have two Content Types:

1: Book

2: Reader

The Book Content Type has a node reference field which is a select list of readers create with the Reader Content Type.

This is all set up and working fine.

Now the issue with my views:

I have a view with is a block containing the Reader fields. What I want to do is have it when the Book node is loaded my block shows underneath with the referenced reader details. Also if no reader is referenced then no block shows up.

I have spent some time in Relationship and Contextual Filters but can't get it to work.

The book URL is formatted like this:

books/[book-title]

I tired using 'raw value from url' in Contextual Filters as setting it to the 2nd argument but that didn't work either.

If anyone can help me out here I would be very much appreciative.

Thanks C

1

Another way is to 'Provide default value' and set to 'PHP Code'. Then use the following to return a specific portion of the URL. The url argument starts from 0 ($theurl[0]).

$theurl = drupal_get_path_alias($_GET["q"]);
$theurl = explode("/", $theurl);
return $theurl[1];
1

Create a simple content view of readers add fields and add a contextual filter of field_book or whatever is the name of reference field and choose option "When the filter value is NOT in the URL" -> "Provide default value" -> "Content ID from URL" and save.

0

Views blocks will not look at path, you need a module like below to pass argument to views block:

function mymodule_block_view($delta){
    $block = array();

    $book_id = arg(1);
    //check $book_id is really a book id
    $nodes = views_get_view_result('xxxx', 'yyyy', $book_id);
    if (count($nodes)):
        $block['subject'] = t('Readers');
        $block['content'] = views_embed_view('xxxx', 'yyyy', $book_id),
    endif;

    return $block; //return empty $block will hide entire block
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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