Hi!
Is it possible to use content_profile variables in a block?
E.g. I have a block about author of viewing node(blog) on my site. (his/her name, imagefield photo, some other content profile fields)
When I want to display data from author content profile in this block, I always do this way:
I take node id from argumens:
if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2))
then I load this node
$node = node_load(arg(1));
then I create sql for load of author profile node
$sql = "SELECT n.nid, n.uid FROM node n WHERE (n.type = 'uprofile' AND $node->uid = n.uid)";
$result = db_query($sql);
$row = db_fetch_object($result);
$node_loaded = node_load($row->nid);
and then finally I can use author profile fields of in a block
$pohlavie = content_format('field_profil_pohlavie_2', $node_loaded->field_profil_pohlavie_2[0], 'default', $node_loaded);
It works for me, however, the question is:
Is there some way how to replace all this steps and to use $content_profile->get_variable in this block?
Theoretically, I can use template file for this block and add it for content_profile variables, but still - I don't how to tell to function $content_profile->get_variable, which account/profile has to be used - in this example it is node author account.
Thanks for your opinion and explanation.
Igorik
http://www.somvprahe.sk
Comments
Comment #1
asak CreditAttribution: asak commentedNice of you to attach the code you use to get it working, i was messing around with this as well...
I'm assuming that if adding the content_profile variable to the block theme then it would display the current users profile, but not sure why that's my assumption...
Comment #2
buckley CreditAttribution: buckley commentedHi,
Thanks for that piece of code
Can the developer make api function call for this? I think there is some fancy lazy loading involvde in the stander way of accessing the data.
Thanks!
Comment #3
benone CreditAttribution: benone commentedigorik: why you cant just use node variables ? What more $content_profile gives you ?
What about that in block body with php filter:
Comment #4
igorik CreditAttribution: igorik commentedHi Benone,
good point.
I replace my code with yours and it works like a charm.
I didn't know about function content_profile_load before.
thanks
Igor
Comment #5
daneyuleb CreditAttribution: daneyuleb commentedWhile content_profile_load would work...if the block is on every page, isn't that a lot of overhead and mysql calls?
That content_profile var, already being set, would probably be preferable. If it was just available in the scope of a block.
Comment #6
Håvard CreditAttribution: Håvard commentedIf you need ACTING USER'S full name you can use global $user->uid instead of $account_id:
If you need AUTHOR'S full name you can do this:
Comment #7
Håvard CreditAttribution: Håvard commented**double post** please delete me..
Comment #8
anggao CreditAttribution: anggao commentedsubscribe
Comment #9
fooltak CreditAttribution: fooltak commentedThank for #3. It works perfect on node page.
How can I load it on blog page by user?
I appreciate any suggestion.
Comment #10
fooltak CreditAttribution: fooltak commentedI could solve it by putting this.
Comment #11
jimajamma CreditAttribution: jimajamma commentedI needed this earlier and was just going to ask/post if this is a good way to do it, so, to continue the discussion, this is what I did in my module:
In the beginning of MY_MODULE.module, I put:
and then in my MY_MODULE_block() where I do my block view:
where I grab, in this case, my cck avatar field that is the user's picture. I know but I didn't feel like using $picture for all sorts of reasons :)
This example uses the uid of the logged in user, but if $node is available, you could use $node->uid instead I would imagine.
Comments? From what I can see, this should even cache things nicely if I am reading the README correctly...
Jim
Comment #12
mobaar CreditAttribution: mobaar commentedSorry to resurrect, but I'm having my own issues on this.
I've created 2 variables, one in the standard Profile module, the other as part of Content Profile module.
Profile module: Variable is named fullname
Content Profile module: Variable is named field_profile_fullname
I'm trying to use phptemplate_username to change the way the display works so it will display the posting user's full name, preferably from the Content Profile module (field_profile_fullname). I haven't been able to get it to work.
Works 100% for the Profile module's "fullname" variable using the following code:
However, as mentioned earlier, it's preferable to use the field_profile_fullname variable found in Content Profile module. Here's the problematic code:
The issue, which I've tested, is that $node_profile->field_profile_fullname[0]['value'] is empty, and thus this code is not executed. I have a feeling it's just my lack of knowledge on the proper referencing. I've double-checked -- the variable name IS correct (field_profile_fullname) and the user I'm testing it on does have a value.
Any help?
Thanks!
~Mo