1

I can create a list of profiles of a specific type. That works great. But what's stumping me is I need a view that has fields that pertain to a specific person. Say for instance you are on Bob's "personal" profile and there is a block that has information for bob's second "business" profile (or any other member's other profiles for that matter). How do I create a block for this profile with relative fields that only populates on demand?....

1 Answer 1

1

Using Configuration

You can use the Views module to access the Profile2 fields.

Below is a quote from ltiong on Drupal.org regarding accessing fields from multiple profile types. The same process applies to accessing a single Profile2 type.

  • 5.1 create View (Show:User)
  • 5.2 add relationship, (User:Profile); give the Identifier a unique name ie 'MainProfile'; select a single checkbox for 'Profile type',
    in my case 'Main profile';
  • 5.3 add another relationship, (User:Profile); give the Identifier a unique name ie 'EducationProfile'; select the other checkbox for
    'Profile type', in my case 'Education profile';
  • 5.4 add Fields to view; select Profile2 field items; use Relationship dropdown in 'Configure field' to associate w/ correct relationship;

You can output as a Block, and use the Page URL to retrieve the correct user ID to load. (For your views context)

Using Code

You can use the profile2_load_by_user(); function to programmatically retrieve Profile2 data.

$profile_data = profile2_load_by_user($user->uid);

See also: profile2_load_multiple()

3
  • Thank you.... I'm a newbie... How do I implement this code... Wouldn't I need arguments, contexts, and relationships??? Sep 21, 2012 at 4:57
  • I added the configuration method from a post on Drupal.org. This should allow you to access the fields in a view that can be output as a Block. I will try to clarify if this is on the right track.
    – Citricguy
    Sep 21, 2012 at 11:26
  • I did the above and was able to get one block... but I need have any control over which content showed... it was always the first user I created no matter what I adjusted. I will try again and see... will report back in a couple hours if it worked or not. Sep 21, 2012 at 13:21

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.