0

I would like to add a wrapper div around Profile2 profiles when displayed on the user account page. I can wrap the title and profile fields by modifying user-profile-category.tpl.php in my theme. However, there's an anchor link to each profile added in profile2.module using hook_user_view: '#prefix' => '<a id="profile-' . $profile->type . '"></a>',.

I can't find a template that will allow me to wrap that link along with its accompanying profile. How can I theme those items together?

1 Answer 1

0

The Profile2 modules implements a profile2_form_alter hook that you can implement in a module. Say you have a module called kelley_profile2, then the function you want to implement is

/**
 * Implements hook_form_profile2_form_alter().
 */
function kelley_profile2_form_profile2_form_alter(&$form, &$form_state) {
  // Check profiles key exists in $form_state.
  if (array_key_exists('profiles', $form_state)) {
    // Iterate through each profile type and add prefix.
    foreach ($form_state['profiles'] as $type => $profile) {
      $form['profile_' . $type]['#prefix'] = '<a id="profile-' . $type . '"></a>';
    }
  }
}
2
  • Thanks for your response, but I'm not sure that you understood the question I was asking. The function you suggested adds a prefix line that has already been added by Profile2. What I want to do is to wrap both that prefix and the content of the profile in an outer div. Nov 8, 2014 at 0:52
  • You're right I misunderstood, and didn't realize that profile2 had a user_view hook that added an a name tag. Sorry about that! I think your best option is to use hook_user_view_alter to change the array structure before it renders.
    – Evil E
    Nov 8, 2014 at 20:39

Your Answer

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

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