1

I have 2 content types, the first one has an Entity reference fields that references nodes of the second type.

I want to build a view (block) that shows some fields of the second (referenced) node when the visitor loads the node id of the first (referencing) entity.

For some reason I think this may be done really straight forward, but I'm not getting it to work.

A similar question was self-responded for the user who made it, but I dont seem to understand the screenshot he posted. How to use Entity Reference and Views

Another question seems to be answered but It looks to me like it lacks some information, as following that 3 points I cant get my block-view to work. Puilling Information From Referenced Entities to Display/Use In A Custom Content Type?

Any ideas?

2

Depending on where you want to create the block/ show the information the way to retrieve the data from the referencing node may vary. Here's a simple example for rendering from within a node.tpl.php:

$referenced_node=node_load($node->reference_field['und'][0]['target_id']); 
print drupal_render(field_view_field('node', $referenced_node, 'field_something', 'displayname'));

This solution makes use of standard Drupal rendering methods/ display suite rendering for your referenced node. Change displayname to the proper display you want to use for rendering, you might want to add a custom one with different settings.

  • thanks @Serpiente, I would like to show a block. My plan is creating a view that provides a block-view of the queried content (some fields of the referenced node). I was thinking that this should be done without additional theming :/ Thanks! – versvs Mar 9 '13 at 8:36
  • Your code works, for sure. That just wasnt the approach I wanted to take. Finally I used an existing EVA field and changing the query of the view totally (querying content of the referencing type and showing the EVA field in the block, rendering the referenced entity in the desired form). – versvs Mar 11 '13 at 10:02
0

Even though the answer by @serpiente just works, that just wasnt the approach I wanted to take: I didnt want to get into theming to solve this.

Finally, I solved the issue using an existing EVA field and changing the query of the view totally (querying content of the referencing type and showing the EVA field in the block, which renders the referenced entity in the desired form, currently resume form).

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.