1

I use the module "entity reference" and I ave "Inline Entity Form" in the node. The first reference has another reference inside. In total there are 3 nests, a grandfather, a father and son. In node.tpl the first parent node how can I print a field of his nephew?

- Node.1
-- Ref. Node.2
--- Ref. Node.3

I want to print a Node.3 field's in Node.1

Thanks so much!

0

There is always more than one way to solve a problem in drupal. How easy those ways are is up for debate, but they exist.

You could:

  1. Make a view with those reference fields as relationships and a nid context filter that would recognize the Node.1 end of the relationships. Set this view to have a block display, and A) put the block on the page with a context or B) summon the view to be rendered by name in your tpl. Or with the function views_embed_view
  2. Make database fetches or entity field queries directly in your node.tpl.php. This is uncouth, as such logic should not be put in the theme layer, but functional.
  3. Forget about node.tpl.php entirely and do this in panels. I'm pretty sure it supports using referenced fields.

The echo $view->render('block_view'); method would be my suggestion to you. Views is a very powerful module, has built in theming overrides (and more if you want more tpls) and can do all sorts of rewrites and manipluations while laying things out for you. Add the ability to conjure it's database bending powers from your tpl with just 6 lines of code, and it is stupendous.

|improve this answer|||||
  • Sorry, I forgot to mention... I already used Views metod, and is ok, but for reasons I do not need to say, I need to use the method override node.tpl – Daniele Sep 14 '16 at 19:42
  • But did you do this in your node.tpl.php? drupal.org/node/951442#comment-5381336 – DeveloperWeeks Sep 14 '16 at 19:46
  • I don't understand how to use the methods that you said. Amongst other things, I need print "rate" (with 5 stars) for any node3 (the nephew). – Daniele Sep 14 '16 at 22:19

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.