Print content profile field on page.tpl.php
trupal218 - October 9, 2009 - 12:49
| Project: | Content Profile |
| Version: | 6.x-1.x-dev |
| Component: | Base module |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Hello,
I am having the hardest time with this and really hoping someone will be able to point me in the right direction =D
I would like to print the user's Content Profile field_firstname where the username is below.
I currently have the following in my page.tpl.php
<?php
print t('Welcome');
?><?php
print l($user->name,'user/'.$user->uid);
?>My setup is that users will fill in their firstname at registration. So when they login I want to say 'Welcome firstname' at the top.
Can someone please help? Thank you!

#1
I'm also looking for a simple way of doing this.
#2
Yes, I think if someone was able to provide us with help on this, it will really allow us to better understand drupal and programming and apply that knowledge to other areas as we work with drupal.
I apologize if the request above is something very simple to others and we just aren't getting it.
Hope someone can help =)
#3
One way to do it is to use the Rules module (http://drupal.org/project/rules) to show the welcome message through drupal's message system.
Install rules module, then:
1) add a new Rule with the Event "User has logged in"
2) Add two actions:
- Load Content Profile (logged in user)
- Show a configurable message on the site
3) Customize your welcome message using Token Replacement ("Welcome [profile_node:field_first_name-raw] [profile_node:field_last_name-raw]")
When the user logs in, your custom message shows up wherever you have $message in your page.tpl.php template.
You could also do it by manually loading the Content profile (content_profile_load()) from your page template, but that might not be a good idea for performance since it would load the profile on every page view. You might be able to do it within template.php but that's above my pay grade.
#4
Hi clockwood,
Thanks for the very nice explanation!
I explored the page.tpl.php method and came up with this:
<?php$welcome_name = $content_profile->get_variable('profile', 'field_first_name');
print l($welcome_name[0]['safe'],'user/'.$user->uid);
?>
Only problem is, when the current user goes to any other user's profile page, the welcome 'user1's first name' at top of page changes to the first name of the viewed user (oh no!).
I'm trying to figure out how to set it so that the first name is only from the logged in user through the php code on page.tpl.php but having a lot of trouble. Any advice from drupal users would be awesome!
Also, I am using template.php for different edits on theme templates but dont know where to start regarding your suggestion on template.php Again, any advice from other users would be great =)
Thanks again