0

In a node type hotel I have an entity reference field to a node type offer. For the offer node.tpl I need to output some fields of the referencing node type hotel.

I have no idea how to get these fields inside the referenced node.

  • Can you still reverse the relations, so instead of referencing from hotel to offer, reference from offer to hotel? – Robin Feb 25 '15 at 13:15
  • I thought about that. But there are about 2000 finished contents which then should be touched... – deelite Feb 25 '15 at 13:37
  • Do you have the knowledge to write an update script? Because my suggestion would be the cleanest way to do this. – Robin Feb 25 '15 at 14:39
  • No, I don't. But referencing to the hotels isn't the cleanest way for the editors. The are editing the offers inline the hotel edit page. Then they need to reference in all offers to the hotel in which they are currently working. – deelite Feb 25 '15 at 14:42
2
  1. You could reverse your relations, then you can show the info you want in the "manage display" tab of your offer content type
  2. You can make a view block of hotels with a reverse relation to offers and a contextual filter on the page url nid of the offer . Then add the view block as a block field on your content type.
  • OK, the view could be a solution. But how can I reverse the relation in the node? – deelite Feb 25 '15 at 14:44
  • May be this module could help? drupal.org/project/content_dependency, haven't tried it out though... – Robin Feb 25 '15 at 14:57
  • When I see it right, content dependency needs a touch to all existing nodes, right? – deelite Feb 25 '15 at 15:22
3

I'd put this in a comment but have no rep so I can't ...

Create a view of hotels as Robin said. The entity reference module provides views relationships that go in both directions , so add a relationship that corresponds to "entity referenced from field yadda yadda" -- sorry I don't know exactly how it'll be labeled offhand but with some trial and error you should be able to find the right one.

Add a contextual filter using the offer relationship on nid, default to content id from url. Be sure to choose the offer relationship when adding fields.

To attach the view to the node itself, you can either use Viewfield or just embed it directly in the template (or preprocess function) using views_embed_view (link)

  • I will do it the view way. So I can use the existing data. But I will use a block. – deelite Feb 25 '15 at 15:21

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.