Hi, im trying to use the cck block module but something weird is happening to me.
When i set a key and a label in a select field,(for instance in a cck text selectbox), it shows the label but not the key in the output of cck block, this is not what I think it is expected, when you insert a key and a label as I discused in issue #262427: Text Select List Allowed Values not entering right values on Database of cck it should use the key as the stored data and not the label.
So if i create a field named field_author and it has a key like pann and a label like peter, is because I'm expecting that the key is going to show in every context that uses the data and the label is just for select boxes and that short things.
I'm trying to make a little workaround editting the module cck_blocks but I dont think this is the way I must do it, for me it is ok if I change the line that shows like:
$block['content'] ='';
to that one
$block['content'] =$node->field_author[0]['value'];
but I would like to use the $delta var like this:
$block['content'] =$node->$delta[0]['value'];
But it doesn't work.
Could you help me? Is there any posible official solution to this problem?, I guess it would be really nice if you can choice what you want to show in the block, the key or the label. Exists that option and Im not seeing it?
Thank you a lot for this module :)
Nadid
Comments
Comment #1
nadid commentedHi again, I would say the problem of this behaviour commes from this line
$block['content'] .= module_invoke('content', 'format', $fields[$delta], $item, $settings['formatter'], $node);
It looks like it always gets the label and not the key, anyone can tell me how it is the right call of this method to get the key?, I would also ask to the cck module.
Thank you.
Comment #2
yuriy.babenko commentednadid,
try this. Go to the content type you're creating nodes of. Then edit it. Then open up "display fields". What are the settings there? It might be configured it show the label but not the actual value for your teasers/full view.
Comment #3
nadid commentedHi Yuriy@yuba,
First of all thanks to answer me :)
It shows on all the options of the field, because what im trying to show is the label in the cck block and not in the content type.
The options I have are , default, trimered and only text , but I think I want hidden and in the block show the key content.
Thank you again.
Any Idea? Im getting something wrong?
Comment #4
yuriy.babenko commentedOh, if you want to display the label in the block but not in node form, you may be better off creating a custom template file for the block and manually printing out the label there.
I'm not sure of this, but the 'content template' module for CCK may help you with this, check it out.
Comment #5
nadid commentedHi Yuriy@yuba,
Again I want to thank you for the response :) You'r so kind :).
Well, actually is that what I want but my problem is how to print out the
labelkey.Im trying to use something like this:
$block['content'] .= module_invoke('content', 'format', $fields[$delta], $item, $settings['formatter'], $node);But that does print the
key and not the labellabel and not the key, and I dont know what to write in the source code to show thelabelkey.I've tryed
$block['content'] .= module_invoke('content', 'format', $fields[$delta], $item['value'], $settings['formatter'], $node);But it shows an & and not what I think it must show(the
labelkey).I know it must be something easy but im totally lost.
Any Idea with this?
Edited
First of all im so sorry, I think i messed out everything.
What I really want is to show the key, I use the label to select and show the key to printout.
I think now i understood the problem, it seams it never shows the key, if I want to to show the key i need to get it by myself from the database because it is used only internally and never showed up.
I think it could be a great option to choice what you want to show, if the key or the label. but it seams nowadays you just can show the label.
So, now, after re-edit my coment, is there any option to show the key?
Oh I almost forget!, I need it showing in the block and not in the body of the node.
Comment #6
yuriy.babenko commentedHi nanid,
Suddenly I'm a little confused as to what you mean by 'key'. Each CCK field has an "internal" name in the form of "field_something," a label like "Something" and some kind of value. Not sure where the 'key' fits in. If you're working with a complex variable like $block or $node, I usually use this to see all the properties/values of the variable:
Try it out in your case and see if you can get anything useful from the $block variable. (This should be done in the block's template file.)
If you still can't get it to do what you want, I would say just make a query to the DB and call it a day; it's simply not worth so much headache :).
Good luck,
Yuriy
Comment #7
adamtyoung commentedAny progress with this? I have exactly the same problem - I want to have human readable labels when users are entering data from the cck form, but then I want to show the label in the view. In my case, the values are integers that I will sum using the excellent views calc ( http://drupal.org/project/views_calc ) module.
Comment #8
marc delay commentedI too am wondering how to use the keys.
I have a field where the user can select an image to use as a backdrop so i use a thumbnail image for the label. This label is about 30 characters long, so its fairly impractical to use it in a case statement or a db_query().
How can I query the key (short name) instead of the label (image string)?
Also using the key to store a numeric value, especially something really huge or irrational, is genius.
Thanks if anyone can help here
**EDIT**
okay okay, i get it now.
you can use the keys with a db_query, you can not use the label that way.
Any time you display the field normally, through views or just viewing the node, the label will always appear.
If you want to display the key you have to use
echo $node->field_whatever[0]['value'](v5.7)You can also use the key for math functions in a db_query or whatever else you can think of.
Comment #9
awolfey commentedI'm trying to print the key in a views-generated block. How would I do that?
Thanks.
Comment #10
awolfey commentedI got it to work in the views block template with this:
Comment #11
Anonymous (not verified) commentedseems to be fixed.