3

On my site I have a series of quizzes.

Each quiz has it's own video (an embedded Vimeo video).

The videos are on a custom content type called 'Video'.

I want to display the video next to the questions throughout the quiz.

I used the Entity Reference module and on the quiz node I referenced the video node.

I used page manager to display the video node next to the quiz. This was ok but when I started the quiz, the video disappeared.

I thought I could create a block with mini panels or with views and display the referenced node but I can't seem to get that to work.

Does anyone know how to display a node on a block that is being referenced by the current node? Or is there a way I can use page manager to display the video when the quiz is in progress?

I am using Drupal 7, and the Quiz module 7.4.

1 Answer 1

2

I worked out a way to do it.

Create a block with some custom PHP.

<?php

//Find current nid
if (arg(0) == 'node' && is_numeric(arg(1))) $nodeid = arg(1);

//Load that node
$node = node_load($nodeid);

//Get referenced entity if it exists
if (isset($node->field_videolink['und'][0]['target_id'])) {
    $refnid = $node->field_videolink['und'][0]['target_id'];

    //Now load that node
    $node2 = node_load($refnid);

    //Display the body 
    print($node2->body['und'][0]['value']);
};

?>

The entity reference field is called 'videolink'. You should enable the block only for the quiz content type otherwise you'll get an error on the home page.

Apologies if the PHP is a little shoddy. I'm not an expert by any means.

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.