Hi Everyone,

I'm trying to theme my user profile page in user-profile.tpl.php.

How do I go about theming the field collections in my user-profile.tpl.php that are part of a profile2 user profile?

I'm using...
Profile 2 7.x-1.1
Field Collection 7.x-1.0-beta2
Drupal 7.6

Thanks for reading,
-Tim

Comments

TimG1’s picture

Status: Active » Closed (fixed)

Hi All,

I figured out a way to do this. Not sure if this is the preferred method, but it's working.

Reading about Drupal Render Arrays really helped me understand what's going on a little better. Also check out the links in the comments in the drupal_render() API docs.

Anyway, I can do something like this to print out my field collection. In my case my field collection is called field_profile_degree.

$profile = $vars['page']['content']['system_main']['profile_main']['view']['profile2'];

foreach ($profile as $key=>$value) {
  foreach($value as $field_name=>$field_render_array) {
    if ($field_name == 'field_profile_degree') {
      $degrees = $field_render_array;
    }
  }
}

print render($degrees);

*EDIT*
Made example a little more clear.

Thanks for reading,
-Tim

faqing’s picture

<?php
// load profile fields
$profile = profile2_load_by_user($elements['#account']);

// then access fields like this
print $profile['main']->field_gender['und'][0]['value'];
?>

Check here:
http://drupal.org/node/1178260

deggertsen’s picture