0

I have a custom content type, let's call it 'parent'. I have another custom content type, let's call it 'child'.

I created a template file where I can display the 'parent' content type fields any way I want: node--parent.tpl.php. By using code such as...

<?php
  print $content['field_city'][0]['#markup'];
?>

I can move fields around and customize the markup, which is great. But how would I also display the parent's children on the same page?

(I don't use Views. I create a content type template file instead because gives me more flexibility for arranging the HTML).

2 Answers 2

0

I know its an old one but it does not seem satisfactorily answered

For drupal 7 usually don't need to mess with template files for such a task.

I would use https://www.drupal.org/project/field_extractor which is a field formatter for entity reference that will let you output any referenced fields from the list of referenced entities (only 1 field though)

If you want to output more than one fields I would suggest the https://www.drupal.org/project/eva which will allow you to create a special entity reference view which you can associate with the referencing entity (parent) and will allow you to output any fields from that entity and format it any way you would format a view. Automatically the view will be available in the display settings of the referencing entity so you can change the order of appearence.

if the previous 2 modules don't seem to help you can try 1 of the following which work with views but they are a little more difficult to setup and I am not going to go into detail here

drupal.org/project/field_embed_views

drupal.org/project/viewfield

drupal.org/project/views_field_view

(sorry my reputation wont allow me to post more than 2 links)

0

How are the children linked to the parent? Do you use an Entity Reference field?

Also, what do you want to display from the children? The titles? The entire, rendered nodes?

If you look up entity_metadata_wrapper (see: Entity metadata wrappers) you can see how to access an Entity Reference field.

You also may want to reconsider Views. Overriding templates for Views can give you a lot of flexibility.

3
  • yes, it's an entity reference field. I want to have access to everything from the children.
    – leonel
    Commented Oct 22, 2013 at 17:25
  • tried the examples, don't work: $node->field_number[LANGUAGE_NONE][0]['value'], $node_wrapper->field_number->value();, $wrapper->label();
    – leonel
    Commented Oct 22, 2013 at 17:32
  • BTW I don't want to use Views because then it gets complicated with custom url aliases. Also, you get pages with duplicated information and links to Views/Nodes get confused, for example: the View for the individual node has the the information are the individual node page.
    – leonel
    Commented Oct 22, 2013 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.