I have created some fields, which can be displayed in other content type by using the following code in my node.tpl.php
<?php print $node->field_birthdate['und'][0]['value'] ?>
It works perfect. But when I use the same code in use_profile.tpl.php, it does not work.
Anyone tried to print the field name in use_profile.tpl.php?
Comments
Comment #1
faqing commentedIn short, how can I display the field name in user_profile.tpl.php?
Comment #2
joachim commentedYou can print $profile2->fieldname, or you can just print $fieldname.
Tip: do dsm(get_defined_vars()); in a template to see everything you have access to.
Comment #3
faqing commentedprint $profile2->fieldname does not work.
Comment #4
joachim commentedIt worked for me.
What is use_profile.tpl.php?
Comment #5
kittell commentedHi Joachim. I am also not able to print $profile2->fieldname variables in user-profile.tpl.php. (We'll just add that missing 'r' now...) For example, including
echo $profile2->field_profile_name_first;gives me a PHP notice:Undefined variable: profile2 in include().echo $field_profile_name_first;does the same:Undefined variable: field_profile_name_first in include().Looking at
$variablesviaecho dsm($variables);gives me only $user_profile as a relevant-seeming variable. Perhaps I missed something indsm(get_defined_vars())?I've printed individual profile2 fields in user-profile.tpl.php in this way:
Notes:
$pidfor each user page by doing adb_query()to the profiles table--I get the pid for the uid that matches the user's$elements['#account']->uid.I look forward to finding out what terribly obvious thing I've missed here...
Comment #6
brightbold@kittel - If the issue status is set to "postponed (maintainer needs more info)" and you provide additional info, you should set the status back to active so the maintainer sees your updates! (Doing this anyway even though you're not the original poster, so that your question will hopefully get an answer.)
Comment #7
TimG1 commentedHey all,
I was wondering the same thing. I'm experiencing the what kittell is in #5. Is this the way we need to access the fields at the moment or is there a more "proper way" to do this?
Like kittell I feel like I'm missing something obvious.
Thanks for reading,
-Tim
Comment #8
TimG1 commentedHi all,
I figured out another way of doing this while trying to print out field collections. See my post here For me the key was reading up on Drupal Renderable Arrays. Please let me know if anyone knows of a better way.
Thanks for reading,
-Tim
Comment #9
faqing commentedwe need to define the profile type, for exmaple main profile:
print $profile['main']->field_name['und'][0]['value'];The following code working for me:
Check here:
http://drupal.org/node/1178260#comment-4590366