By cre8d on
Hi,
I have succesfully created some fields for my users' profiles. I would like to be able to show some of these each time they post a comment on the site (e.g. their location).
How do I do this? My theme is based on phptemplate.
I have tried putting in the name of the field in the comment.tpl.php, e.g. $profile_location but it returns nothing.
Any help appreciated.
Comments
Sorry
Sorry I didn't mean to post this twice.
since nobody else picked up on this..
Hi Cre8d,
I don't have a definitive answer for you...but since nobody else picked up on this, I thought I would chip in.
As I understand it there are only a certain amount of variables available via the phptemplate engine for the comment.tpl.php file.
So (I stand corrected) I think you have to insert a few lines into your phptemplate file where the variables are set for comment.tpl.php and add in a $user_location variable, for example, that references the corresponding profile field you have setup.
It's a very very good question....and I for one, would love to see an example of how to do this for you're specific needs. Phptemplate is superb, but, for newbies like me who are not proficient in php it's a bit of a struggle to get to grips with how things are done.
if you haven't come across this already, there are handbook pages for Making additional variables available to your templates, but there are no simple examples for newbies...
Would be keen to see an example of how you/someone else has done this.
Dub
DUBLIN DRUPALLER
___________________________________________________
A drupal user by chance and a dubliner by sheer luck.
Using Drupal to help build Artist & Band web communities.
Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate
Snippet to show profile fields in comments
This is a snippet to lay the ground for showing some profile fields in comments in a phptemplate theme. Paste it into the top of comment.tpl.php in your theme. That might be the one in the phptemplate directory. Then write the code that shows the profile fields you want as outlined below.
You can get a formatted profile field by calling
The title from
admin->settings->profileis available inBy using the title member variable you only have to update in
admin -> settings -> profileto have the change reflected here. The variable$have_profilewill tell you whether the current comment has a registered user associated with it and one or more profile fields are succesfully loaded. The$commentatorvariable contains the user object and the$fieldsarray contains all fields defined inadmin->settings->profile.Example:
Note that the code will refuse to show private fields by default.
It should be noted this chunk of code does use some resources as it loads the commentators user object on each comment rendering, and a better approach performancewise would be to change comment.module. Also, I suppose many don't like this mixture of logic and presentation. Personally, I don't think it's such a big deal here.
Here is the code to paste on top of comment.tpl.php
Final note: Updated the code, use current version please.
Another example
This one automates the process a bit at the expense of flexibility.
If you want all fields filled out by the user outputted in this manner, use this code:
Brilliant
Thanks everyone - I will give it a shot now.
List profile names ordered by contents of profile list field
Hi Adagio,
Thought you might be able to help with this related snippet request.
I am trying to list profile names and maybe photo fields ordered by the contents of a list field (professions) filled out by the members.
So that I would get an alphabetical list of Professions with members names and photos listed according to the profession they selected.
Any pointers would be greatly appreciated.
Getting a field from the user profile showing in the comments
Excellent contribs!
Apache is bandwidth limited, PHP is CPU limited, and MySQL is memory limited.