Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm trying to print a field (in my case - the field 'field_state') from the 'uprofile' node, created by CP, into the author pane block.
this, for example, is working great :
echo $content_profile->get_variable('uprofile', 'title');
but this one isn't (giving 'Array'):
echo $content_profile->get_variable('uprofile', 'field_state');
Sorry if that's a really basic quastion, but I folowed your comments and the ones in the author pane module and I can't get this to work.
Thanks.
Comments
Comment #1
andreiashu CreditAttribution: andreiashu commentedHi tsi,
So in fact you are trying to print out the value of a CCK Field that is on a CP node type, right ?
(I really don't know how $content_profile->get_variable('uprofile', 'title'); works for you)
Comment #2
tsi CreditAttribution: tsi commentedYes, I guess, thought it should be simple enough.
Comment #3
andreiashu CreditAttribution: andreiashu commentedThis could help: http://api.audean.com/api/function/content_view_field
Comment #4
tsi CreditAttribution: tsi commentedThanks, but this won't do any good unless you can direct me to what to do with that function.
Second, what about all the theming options metioned in the README file :
Isn't there somthing here that supposed to do what I am looking for ?
thanks
Comment #5
asak CreditAttribution: asak commentedThe problem is you have nothing in $content_profile (I think)
Anyway, to print a cck field you should get the node in $node, possibly:
$node = content_profile_load('uprofile', $user->uid);
and then use you something like this:
print $node->field_state[0]['value'];
to print the field. notice you need $user as well.
Comment #6
Rosamunda CreditAttribution: Rosamunda commentedI´ve managed to make this work, but I have to put the code at the very ending of my node template, because it seems like after it loads the content profile, won´t show anything else from the original node.
Is there a way to "cut off" the loading of content_profile_load?
Thanks!!
Comment #7
andreiashu CreditAttribution: andreiashu commentedI just read through the comments of Michelle and Fago in #316009: add content profile docs for themer and realise that this issue is in fact related to CP. So changing back the subject.
@asak: about #5: I think it is better to use content profile's method of loading data than CCK's. Also I have the slight feeling that your method in #5 could open up a security hole (see fago's comment #20 on #316009: add content profile docs for themer).
@tsi: when you do
what does
print_r($variables);
output. The variable 'field_state' does not exist in $variables but we must find out why (probably you are looking for the wrong variable name ? ).Comment #8
asak CreditAttribution: asak commented@andreiashu - I tried the CP method with no success. about security - this needs to be enclosed in a check_plain():
Comment #9
tsi CreditAttribution: tsi commented'field_state' is a cck field I'v created so you should replace it with whatever field you would like to print.
The code I'm using right now to make this work is :
*replace x with the field's name
Comment #10
YesCT CreditAttribution: YesCT commentedI think in order for the permissions per cck field to work, it needs to be run through node_view, not only check_plain...
so it would be something like print node_view(node_load($nid)); and print node_view(content_profile_load($uid));
... except I tried that and it did not work. (nothing gets printed after "print name").
I tried, logged in as user 1:
Comment #11
andrenoronha CreditAttribution: andrenoronha commentedsubscribing
thanks for this post :)
Comment #12
Bilmar CreditAttribution: Bilmar commentedsubscribing
Comment #13
uomeds CreditAttribution: uomeds commentedSubscribing. About to try #9.
Comment #14
uomeds CreditAttribution: uomeds commentedThe code in #9 is working beautifully for me! Thank you.
One request - Does anyone know how to limit the number of characters from a field that are printed? For example, I am trying to print a date field that is only a year value (4 digits, eg. 2013). However, it is printing the full stored value as
2013-00-00T00:00:00
----------------------
edit: Never mind. Figured it out.
Comment #15
andrenoronha CreditAttribution: andrenoronha commentedYou may try this more elegant way:
Y for year
m for month
d for day
etc.
Comment #16
Bilmar CreditAttribution: Bilmar commentedyou can refer to http://php.net/manual/en/function.date.php for different formatting options to use with #15
Comment #17
uomeds CreditAttribution: uomeds commentedThanks a.luiz.n and trupal218. I tried that method and it works nicely but seems to be subtracting one year from each date. Is there any way I can make it display Y+1 to correct for this?
Also, I am now trying to take it one step further and replace my default 'user picture' field in my author panes with a custom uprofile filefield imagefield (field_profile_picture).
I need the following statement:
to define the following variables:
1) $image_filepath = stored url for the picture in that field
2) $alt = "(username)'s picture"
3) $title = "(username)'s picture"
4) $attributes = unknown, blank I think
So that I can print the new uprofile pictures, with any given 'preset_name', via the following standard imagecache string:
I feel this would be an awesome way to let uprofile take over one more core responsibility and make the 'user picture' far more flexible in how in can be implemented.
I know it might be getting tricky, but any help with calling and defining those variables would be great.
Thanks.
Comment #18
andrenoronha CreditAttribution: andrenoronha commenteduomeds,
let me see If I got what you want...
You want to print the imagecache-preseted user picture which was uploaded with a fileField in a content profile?
I made my own tricky way to do this, tell me if that's what you want....
Comment #19
uomeds CreditAttribution: uomeds commentedYes, a.luiz.n, that is exactly correct. The field is a filefield type imagefield, provided via uprofile. I want it printed using a specified imagecache preset.
Any way to do this would be great. It's the last function my site needs.
Thanks.
Comment #20
andrenoronha CreditAttribution: andrenoronha commentedOk.
I used this node: http://drupal.org/node/432854 as reference, but their solution didnt work for me...
That's what I did:
1. I found and implemented this good function that returns a string between strings that I pass as parameters:
2. I overrode this function to return the picture:
and Voilà
I hope it helps you... At least hope you understand my code...
if not, try to figure out how the path to the imagecached user picture is.
Comment #21
uomeds CreditAttribution: uomeds commentedI tried adding the following to my advanced_profile_author-pane.tpl.php:
But nothing happened. The page just loads no different with or without it. I didn't enter a proper default because I don't intend to have a default.
I've checked and both listed directories exist and are correct:
However there is only a "demo image" in ../imagecache/authorpane_profile/, so imagecache is obviously for some reason not being triggered to activate by the above code.
Any ideas?
Comment #22
uomeds CreditAttribution: uomeds commentedNever mind. I got it working via:
http://drupal.org/node/470004#comment-1626220
Comment #23
HongPong CreditAttribution: HongPong commentedI found this when looking for how to print filepath CCK filefields. Like so, if field_episode is a filefield:
print $node->field_episode[0]['filepath']
Comment #24
ressa CreditAttribution: ressa commentedI needed to populate the "Default value" field of a User reference (Customer unit zone) with a User reference(field_partner_reference) from the current user's Content profile ('customer_unit').
A user can create several Customer unit zones, and in the end both Content profile ('customer_unit') and Customer unit zones point to the same partner. I hope it kinda makes sense... 8o)
So I needed to refer the new Customer unit zone to the person ('partner') responsible for the Customer automatically, this did the trick:
Comment #25
tevih CreditAttribution: tevih commentedHello,
I must be pretty thick, as I can't get this to work! I'm trying to print a content profile cck field in the author pane, as the OP. I confirmed the name of the field by doing this:
Which let me know that the field is field_profile_company. So I used the following code as in #9 to print it, in the author pane template file:
But it didn't display anything. And yes, there is data for that field.
What am I doing wrong?
Comment #26
tevih CreditAttribution: tevih commentedUgh!! I spent 5 hours trying to figure out how to theme the author pane, and less than 5 minutes after posting in frustration, I figure it out!!
I changed:
$node = content_profile_load('uprofile', $account_id);
to:
$node = content_profile_load('profile', $account_id);
I see here that other people are using 'uprofile' in their code - why the difference?
Comment #27
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 #28
Michelle@tevih: It's the name of the node type so it depends on what you called your node type.
Michelle
Comment #29
tevih CreditAttribution: tevih commentedThanks Michelle - that makes sense.
Comment #30
guntherdevisch CreditAttribution: guntherdevisch commentedHi all,
I have a custom content type named 'CV', which is also a Content Profile field.
I'm trying to print out the value in my user-profile.tpl, but it doesn't work. Can someone help? My Content Type is a file field. I want to show the value + make it clickable to the users.
I allready tried using the following:
Thanks in advance!
Gunther
Comment #31
mashizhao CreditAttribution: mashizhao commented#9 works like a charm! Thanks for sharing!
Comment #32
Priyanka Singh CreditAttribution: Priyanka Singh commented#9 works perfectly..thanks @tsi...
Comment #33
sjiuh CreditAttribution: sjiuh commentedHow i got it to work
opdrachtgever_profiel = node type
field_abonnement_vorm = desired field
Hope it helps someone,
Maarten
KA FileMaker Pro developers