I want to create a custom user profile need some help in how to call custom profile fields.

The direct method fo $account->(field name) is simple and what is used in all the examples.

What I want to do though is pull all the custom profile fields in a particular category and display them in order of weight. I also want to exclude any field not set as public.

How to do this is straight forward, but I'm missing how I call those attributes of the $account or $user_profile variable and would appreciate any help.

Comments

dnewkerk’s picture

Example:
<?php print $account->profile_gender; ?>

Also note that you can make Views blocks (use the view type "User") using user profile fields, and have those blocks displayed at the user profile path... this is my personal preferred method, since I've found most often I end up wanting to mix in a variety of other blocks on the profile, and getting everything laid out the way I want when some parts are blocks and other parts are hand-coded theming in user-profile.tpl.php ends up being very tricky (if everything is in a block, it is a lot easier - use regions or Panels and you're set).

If you use regions, you can add the regions "just" to user-profile.tpl.php to make your block management tasks easier for yourself. Here's an example of one on my profile:

<div class="clear-block">
  <?php print theme('blocks', 'profile_bottom'); // "Profile bottom" region, add blocks via Blocks UI ?>
</div>
Streamweaver’s picture

Thanks for the reply.

Calling individual fields is easy enough and I'm not having a problem with it. What I'm having difficulty with is calling all profile fields under a catagory and their associated attributes.

For instances I have 'profile_fax', 'profile_phone', 'profile_team' all as custom profile fields under the catagory "Contact Information". Each has weight based on the ordering I give them in the drupal interface and a display value (public, hidden, etc).

What I want to do is get all attributes under "Contact Information", order them by weight and iterate over that displaying those marked as public.

From all the examples calling the value of an attribute is easy (i.e. $account->profile_fax) but I want to do more with it and am having trouble.

I've tried calling $account["Contact Information"] which looks like what it should be from print_r of the $account variable but I'm missing something there because it breaks the site. Also, not really grocking how I'd call the weight of a field or the privacy attribute..

Any thoughts would be helpful.

mndonx’s picture

Hi Streamweaver - So are you working from within the user-profile.tpl.php template file? Do you have devel module installed?

If so, you can stick this in your file:

<?php dpm($account); ?> or <?php dpm($user_profile); ?>

Those will print out all the variables and their related attributes.

Does that help?
Amanda

Streamweaver’s picture

Thanks for the reply and see my reply above. I've done a var_dump but am not getting something about how I'm suppose to call those attributes. I've tried based what I see there but It's breaking the site.

mndonx’s picture

Hi Streamweaver -

One thing to check when you are printing complex variables is whether they are part of an object or an array.

If it is part of an object (like $account) it will look something like $account->name. If it is part of an array, like an attribute, it might look like $account->content['#value']. An attribute, like weight, will be preceded by a # (hash tag). If you use dpm($account), it will tell you whether an item is part of object or an array.

It's hard to say without seeing your variable print-out and what you are trying to do.

When you print your variables, do you see weights attributed to your fields?

aac’s picture

Subscribing!!

---~~~***~~~---
aac