Theming User Profiles

On this week's Mustardseed Media Video Podcast, Bob gives you the basics on how to theme user profiles using Drupal's core Profile Module. He talks about print_r, the $account variable, and puzzles over why the user-profile.tpl.php doesn't mention a crucial element. All this week!

Nice Podcast. It came at the right time. I was struggling with theming user profile. Thanks Bob.
What about the "Content Profile" and its method of treating profile of each user as node ? Don't you consider it as a better approach for theming user profiles ? Bob, when you are going to cover something on "Content Profile" ? :)
Hey Atul... As I mentioned in the podcast, things like content profile module are themed exactly like nodes...because they ARE nodes. So, there's no difference at all on how you theme those vs. theming a blog or a podcast node or anything else. I won't spend alot of time getting into it but let me say this: Before Views 2, I always did my users as nodes (using bio module, which content profile is the successor to). The main reason for this, however, was because Views 1 only worked with nodes, not users. With Views 2, this is no longer a reason to use a profiles-as-nodes approach (you may want to check out this podcast for more talk about this concept). There are other reasons you may still want to use something like content profile...maybe you want to attach a taxonomy or you want to be able to use CCK fields such as file uploads, etc. However, I've generally found ways to accomplish the same thing using core profile module. The only reason I ever don't use profile module now is if I need to do COMMENTING on users. There are ways to make this happen with core profile module (such as using a CCK node type named "user comments", a user-reference field, and a Views block) but it's MUCH easier to just make your profiles into nodes and use the commenting system. (plus its better on load times). So, why not "Content Profile"? After using the users-as-nodes approach for a long time I see that, for me, it no longer makes sense except for in special circumstances. That may or may not be the case for you. Good luck!
Thanks Bob. That was a wonderful Clarification. Thanks again. :) You cleared the haziness in which I was surronded. I am waiting for your next podcast.
Bob, (and others) I think you'll get a lot of value from using Devel module's dpm() function. It's print_r on steroids. You'll need to install devel module, but once you do, you can use dpm instead of print_r. This will use some nice developer stylized output using a library called krumo(which is included in devel). dpm is short for Drupal Print_R in Message area. You can also use the dvm equivalent if you want a var_dump instead. dpm($account) will make things look nice and pretty (and out of the way of viewing your results)! Note: if you're using a non admin account (not user 1) then you'll need to make sure it has the permission 'access devel information'. Enjoy.
Good tip on using Devel for this, Matt. Generally, since most of what I do it theming, I find the devel module too heavyweight for simple tasks like printing out my variable contents. I agree, however, that if you don't mind the overhead that it spits out a much nicer version. Normally, I just don't even install devel because I tend to use one or two small functions out of it's 10 zillion :) The themer module in devel is nice, but I generally don't use it because (if you know how drupal calls templates) it is generally telling me stuff I already know. I'd say if you've got devel installed already (or are going to install it for some other reason) than using it to print your variable information is definately the way to go. But, if you're like me, and don't care to use most of it's functionality, I still recommend using print_r. Thanks for adding to the discussion, Matt!
Bob, That php if statement you put in at the end does not seem to work for me. From what I could see, it should look something like this for my profiles: <?php if($account->profile_profissao){print $account->profile_profissao; } ?> If works fine in actually displaying the field if the user has it filled out. However, I still get the black line and space if the user has not filled out this field. I also posted a similar question over at G&G regarding user roles/permissions and the user-profile.tpl.php page. Furthermore, I have been all over the Drupal site, forums, and done several google searches and I cannot seem to find a clear cut tutorial on using if statements in Drupal. They also appear to be different in from one version of Drupal to another. Any help you (or anyone) can provide would be awesome. Thanks and Feliz Natal jason
Hi, Thank you, for you podcast. Can you show me the way to theme the textfield with multiple vulue (%value). If i make <?php print $account->profile_example-field; ?>, it only shows me a text of my values without links.
to theme the textfield with multiple values you'll want to create a PHP foreach loop. You can find out more about it here.
This little vid really got me going on the test site for our church redesign. Your print_r trick plus this post about including post lists in profiles (http://drupal.org/node/38538) has got me making some crazy cool profiles. Thanks!
Hi Bob, Further up you mentioned that you can usually get around using something like Content Profiles by using the core Profile module. I'm interested how you get around things like file uploads and (for example) taxonomy checkboxes. I'd love to be able to dump Content Profile but I can't see a simple way of doing so (i.e. without too much theming/hacking). Thanks, Your videos are a godsend. B
Man, I must be stupid because I'm stuck in one area and can't follow this video. I'm using drupal 6.10. I created the user-profile.tpl.php and uploaded to my theme under sites/all/themes/lightfantasic I made the changes in user-profile.tpl.php by adding <?php print_r($account)?> uploaded the file to my server under my themes directory, but HOW DO I SEE the list of variables? I'm logged in and if I go to http://www.mysite.com/user I just see the the profile as it was without a list of variables. I cleared all cache (both drupal's and browser) but still see no list. I went into admin hoping to somehow find it there, but no go. So I'm lost to where I see this list of variables after I upload the user-profile.tpl.php to my theme directory with the above changes. Since I could not find the variable list per the video, next I just did the same test you did in the video by adding test uploaded again, went to My account, but saw no changes. I must be overlooking something obvious or this does not work for 6.10. Please tell me what I'm doing wrong? Thanks steve
Steve, Just a guess, but what if you tried going to http://www.mysite.com/user/2 or some other actual user's profile page instead of just http://www.mysite.com/user
this is the string to get the user_picture <?php print $account->content['user_picture']['#value']?>
In your podcast you used print_r to get the variables. A way to get the same thing without the need to know the $account or any other variable is to use this code below. It works on any example.tpl.php file! <?php print ''; var_dump(get_defined_vars()); print ''; ?> Works for me every time! -Jason
Thanks alot for all tutorials I'm entirely agree to Matt Petrowsky regarding using devel module and using dvr($); or dpm($); instead of print_r($); also i recently use module realname to switch those "horrible" username into normal humane name, such as content of field profile_fullname in this tutorial again, thanks for all tutorials, keep up the great work
Another great video. Thanks for the tip on the account variable.