0

I have a content type (let's call it course) and a content type named edition (if we have a course named "English 101", we can have "English 101 - June", "English 101 - July" and so on.) For this, I used Entity Reference.

If I see the node "English 101-June", I can see the "parent" node being rendered (I chose that on Manage Display". What I want now, is when I see the "parent" node "English 101" the full list of referenced nodes to be rendered. How can I do this?

1

There are a number of ways to get reverse references. Probably the best option is to use the Views module. The reference module allows to create a reverse relationship in the view. You could do something like this:

  • With the Views module, create a view of nodes with a page display at path 'myview' ;
  • Set up your view to display only the title of each node ;
  • In your view add an argument that matches your node id ;
  • In your view add a reverse relationship that matches the field that is used to reference content. The name to use for the relationship would be something like field_my_reference_field (reverse)

Save the view, now go to 'myview/1' and you will see all the nodes that reference node 1. You could also get this displayed in a block, or as a field using the ViewField module.

If you don't want to use the Views module, then you can use the Nodereferrer module to achieve this. However in that case you can only get the list as a field - you can't get it as page or a block.

0

You can create a first view to list all your courses nodes.

And next, in a custom module, you display the references (with antoher view who accept an argument of the parent reference nid)

function custommodule_entity_view($entity, $type, $view_mode, $langcode) {

  list($id, $rev, $bundle) = entity_extract_ids($type, $entity);
  switch ($bundle){
  case 'course':
    if( $view_mode == 'full' ){
      $entity->children['children'] = array(
        '#markup' => '<h1>Childrens</h1>'. views_embed_view( 'childrens', 'default', $entity->field_course['und'][0]['nid'] ),
      );
    }
    break;
  }
}
  • Maybe I didn't explain well. What I want is to list the nodes when I am viewing the "parent" node, not a list with all nodes and the references – noitib Apr 8 '13 at 15:04
  • you can add a condition to display only if the node is in full page : if( preg_match('#^node/.*#', $_GET['q'], $matches) ); – pico34 Apr 8 '13 at 15:12

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.