I've been using the Front End Drupal book to help me along with my first drupal theme project, and it suggests creating a page-user.tpl.php to customize your user profile pages. I customized the layout just fine, and then began trying to insert profile data from the database, but here is where I'm utterly failing.
After reading lots and lots of support topics, I tried to change my page-user.tpl.php to user-profile.tpl.php as none of the calls to the profile variables were working. But when I rename page-user to user-profile drupal doesn't seem to notice it anymore. Now my pages are displayed according to what seems to be page.tpl.php, but it just looks off.
So my question is a two-parter:
1. What exactly is the difference between page-user.tpl.php and user-profile.tpl.php, and which should I use?
2. If its possible to use page-user template file, how do I make calls to the user profile data?
Thanks!
- Ryan
Comments
ive been using user-profile
ive been using user-profile on my site, and havent had problems. did you use the user-profile.tpl from the user module folder. I copied the tpl from user modile to my themes folder. then at the bottom i just changed
to show what i wanted to show.
Some things (I think) I've
Some things (I think) I've discovered:
1. It seems like user-profile.tpl.php behaves much like a special node template for user profiles. Page-user.tpl.php is just what it says it is, a page template file for anything under the /user directory, including login, registration, etc... user-profile.tpl.php comes into play via the $content variable in your page templates.
2. Using Advanced Profile Kit can mess up this functionality. It bypasses the user-profile.tpl.php in favor of the particular panels template used by the advanced profile kit. I'm not sure, but I'm suspecting Content Profile is doing something here too.
And yet I'm still unable to print profile variables onto the page. Using this post http://drupal.org/node/228485 as inspiration I tried these in user-profile.tpl.php:
print $profile['profile_section_heading_1']['#value'];print $element['profile_section_heading_1']['#value'];print $profile->profile_section_heading_1;print $element->profile_section_heading_1;None of these work. What the heck is going on?
- Ryan
EDIT: Ok it seems like the $profile variable in user-profile.tpl.php is an array with variables for each of the sections set up in /admin/user/profile. Thats great except that each variable is filled with pre-formatted html output. This seems really limiting. Isn't there a way to just print a variable to a page using the machine language name created when the field was created?? Or do I really have to make a new template file for each category and item in the profile I want themed differently?
what you trying to put on the
what you trying to put on the page? just profile fields or blocks/views or something also.
All i put is
where h2 is the title could change it to h1 or h3 and change About me to the title of your page or profile field.
then profile_Me, Me is the field to display/form name
No info here, change it to display what you want if the user hasnt filled in any information.
page-user.tpl.php
Hi,
user-profile.tpl.php doesn't quite do the job because it won't allow you to step back far enough to address the page elements.. (wrappers, page title, edit link, header, etc)
the best way to handle this that i've come up with is a combination of 4 files:
page-user.tpl.php
for the furthest-back structure of the page
user-profile.tpl.php
for the profile-specific elements which can be accessed as discussed in other posts on this page and also this one: http://drupal.org/node/35728
page-user-register.tpl.php
set to match page.tpl.php in order to keep page-user.tpl.php from overriding the register page -- you can use require_once ' page.tpl.php';
page-user-login.tpl.php
set up in the same way as page-user-register for the same reason.
EDIT:
If you want your page-user.tpl.php to recognize that the the user/*/edit page is being hit, use the following:
-trevor
Solution!
Found a solution. Near the top of your user-profile.tpl.php file put this:
profile_load_profile($account);Then wherever you want to print a particular variable into your template you put:
print $account->machine_field_name;Security
Do make sure those fields have been run through check_plain or check_markup unless you like having hackers take over your site. :)
Michelle
Theoretically only our
Theoretically only our clients (who should have no interest in hacking us) will be using this functionality.... but I should do this just to get in the habit anyway.
Thanks Michelle, great comment!
- Ryan
I would like to use the
I would like to use the $account variable on page-user.tpl.php instead of user-profile.tpl.php because it only reflects on the $content variable and if I breakdown the $content variable it comes all css formated. Is there a way to use $account on page-user.tpl.php?
.
Michelle
Thanks so much!!
Thanks a lot for this...this is precisely what I needed in order to get everything running as I wanted! Extremely helpful!
Subscribing!!
Subscribing!!
---~~~***~~~---
aac