Closed (duplicate)
Project:
Content Construction Kit (CCK)
Version:
5.x-1.x-dev
Component:
General
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
6 Oct 2007 at 08:21 UTC
Updated:
26 Oct 2018 at 00:10 UTC
Jump to comment: Most recent
Comments
Comment #1
ZrO-1 commentedI found the (partial)* solution you are looking for. You can use:
<?php print($node->content['field_my_field']['#value']); ?>to pull the entire formatted field for your content type. This will display the field the way you have specified in the "Display Fields" tab of your content type - including the label.* I say partial because I don't know if this will work on a "multiple values" field. I havn't tried it yet. (I am new to drupal).
Hope that helps...
Comment #2
guidot commentedThanks, I tried that, and it does print the themed label plus content.
I need to process the content separately, and I tried but could not figure out how the expression has to be modified to give me just the label.
Comment #3
ZrO-1 commentedhave you tried
<?php print $field_my_field[0]['label']; ?>? That is from the CCK theme folder example template file, I just replaced 'view' with 'label'. I think that should work...Comment #4
guidot commentedDon't remember, if I did. I tried so many variations, so I give it a try it now.
Let's see...
...no, nothing. I also tried to replace
['label']with['#label'], but still nothing gets displayed.Comment #5
altavis commentedI'm also interested in field label theming. If someone knows the solution please post it.
Thanks in advance.
Comment #6
jeffrey.dalton commentedI did quite a bit of research on finding a posted solution to this issue as well and came up short... is this a bug in CCK?
Comment #7
CMatters commentedI wouldn't call it a bug, perhaps just a feature left out or not well documented. You can override the theme of each field (through template.php) and it gives you the label. Here is the expert from CCK's README...
The supplied template.php code is...
SOLUTION!?!So there is the ability to use field labels when theming just certain fields.. but in a complete node theme? Good question. I would say so, I tried a couple of things but it made my head hurt so I went on to try something else. Here's the workaround I settled one. I use
$node->content['field_add_detail']['#value']as previously discussed and use two PHP functions, strpos and substr, to trim it down to JUST the label. Here's some code:First I created a function at the top of my node-contenttype.tpl.php.
Second, when I coded the actual output I called my new function to format (chop?) the label. Here's an example:
Voila, ici! It's an ugly hack but it works for me. I hope that it works for you.
Comment #8
tmai commentedHello have the same problem with printing field's label, I tried your guide, it partially works, because the label of number value didn't show when I use ['#value'}, do you have any idea for this, please share it with me.
Thanks
Thuan
Comment #9
xjmI'm having a similar issue; I want to be able to get and use the label value separately from the field value (in my case, in a table). I've considered using regular expressions to parse out the label from the [#value] array element, but obviously some sort CCK solution would be preferable. Has anyone looked into a patch for CCK that would add the label alongside the value, weight, etc. to the data in the $node object?
Comment #10
xjmUpdate -- I just found this patch:
http://drupal.org/node/209229
I have not tested it yet but it may be a solution.
Comment #11
xjmI created a revision of the patch at:
http://drupal.org/node/209229#comment-886855
Patch file is at:
http://drupal.org/files/issues/add_labels_cck_1_7.patch
Please review/test there.
Comment #12
jmlavarenne commentedCareful - I don't think $node->field['#value'] is run through any filters.
Comment #13
xjmActually #value is filtered and then some; it includes an HTML-rendered label, which is why I would have had to regex it out. Anyway, I used the patch (linked above) to get the functionality I needed.
Comment #14
xjmMarking as duplicate; see http://drupal.org/node/209229.
Comment #15
jmlavarenne commentedI always thought the filtered information was $node->field['#view'] - that's what I use.
Comment #16
Anonymous (not verified) commentedThis is a very old thread, but as I am fairly new to drupal theming and found the solution myself after searching for days, I am posting it here for future reference.
The code for displaying labels is:
<?php print $node->content['field_name']['field']['#title'] ?>The source for this is http://www.davidnewkerk.com/book/30 however if your fields are part of a group, then you'll find you need to modify it to the following code.
print $node->content['group_specs']['group']['field_name']['field']['#title']I figured that out after reading up my arrays. Cheers!
Comment #17
xjmThe issue was for D5.x versions of the module. It was patched in the D6 version, but not in the D5 version.
Comment #18
unik commentedComment #19
Michsk commentedmind sharing your snippet, i can't figure out what value to put where. Maybe a real life example would help.
Comment #20
bushman commented<?php print $node->content['field_name']['field']['#title'] ?>These works! GREATE Printing label of cck field
Comment #21
Anonymous (not verified) commentedI know this Fred is old, but maybe it still helps someone.
#16 works! At least, when your field is part of a group.