I'm trying to print a field from an entity reference field - but I don't have a clue how to do it!
A bit of background: I've got two content types - master and variation. Variation includes an entity reference field, pulling in fields from the referenced master. But they share an image field. When the variation's image field is empty, I need the master's to display in its place. On the other hand, if the variation's image-field is in use, the masters needs to be hidden. My first thought was to use a display mode, but as you can see I need a little more flexibility than that.
So the details.
A dpm($node) on a variation node gives me:
... (Object) stdClass
field_master_reference (Array, 1 element)
--und (Array, 1 element)
----0 (Array, 3 elements)
------target_id (String, 2 characters ) 11
------entity (Object) stdClass
--------(list of lots of strings which I'll leave out for concision)
--------field_country (Array, 1 element)
--------field_publisher (Array, 1 element)
--------field_catalog (Array, 1 element)
--------field_main_image (Array, 1 element)
----------und (Array, 1 element)
------------0 (Array, 13 elements)
--------------fid (String, 2 characters ) 10
--------------alt (String, 0 characters )
--------------title (String, 0 characters )
--------------width (String, 3 characters ) 518
--------------height (String, 3 characters ) 360
--------------uid (String, 1 characters ) 1
--------------filename (String, 21 characters ) testimage99_r1_c1.png
--------------uri (String, 38 characters ) public://masters/testimage99_r1_c1.png
--------------filemime (String, 9 characters ) image/png
--------------filesize (String, 4 characters ) 4627
--------------status (String, 1 characters ) 1
--------------timestamp (String, 10 characters ) 1366482521
--------------uuid (String, 36 characters ) 67gf4dbb-0a37-4ee9-893e-6g51e3et33c1
------access (Boolean) TRUE
(miscellaneous other fields which I leave out)
I've bolded the relevant structure. From it, how do I print field_main_image (as a fully rendered image)? Sincere thanks to anyone who can help me with something that has perplexed me since Wednesday.