Drupal theming nested field collection

253 views Asked by At

This is how my content-type looks like image what is the best way to theme this ? I used views and views-field-collections-items before. but I just couldn't get the 3rd field collection values i.e Revenue info as per the image.

Suggest a best possible way to theme this content type please!

1

There are 1 answers

0
Entaro On

I suggest to use templates, it is much easier to style things as you want. Here is an example for your particular case:

<?php
  $field_nation = field_get_items('node', $node, 'field_nation');
  foreach ($field_nation as $nation) {
    $fc = field_collection_field_get_entity($nation);

    // Nation name
    $field_nation_name = field_get_items('field_collection_item', $fc, 'field_nation_name');
    $field_nation_name = $field_nation_name ? $field_nation_name[0]['value'] : '';


    // Another nested field collection
    $field_companies_info = field_get_items('field_collection_item', $fc, 'field_companies_info');

    foreach ($field_companies_info as $company) {
        $fc2 = field_collection_field_get_entity($company);

        // Company name inside second field collection
        $field_company_name = field_get_items('field_collection_item', $fc2, 'field_company_name');
        $field_company_name = $field_company_name ? $field_company_name[0]['value'] : '';

        // Industry inside second field collection
        $field_industry = field_get_items('field_collection_item', $fc2, 'field_industry');
        $field_industry = $field_industry ? $field_industry[0]['value'] : '';

        // Another nested field collection for Revenue information
        $field_revounue_info = field_get_items('field_collection_item', $fc2, 'field_revounue_info');
        // ..... And here another foreach similar to those above
    }

  }
?>