I use CCK to create a custom node type, named NODE. I add a field FIELD in it. Its label is LABEL, and type is text, and it is not a multiple value field. I create a node-NODE.tpl.php file. In the file, I write the FIELD's value with:
print content_format('field_FIELD', $field_FIELD[0]);
All is well so far. Now, I want to put LABEL before the value. Surely I can just print "LABEL: " in the file, i.e.
print "LABEL: "
But perhaps I will change LABEL to NEWLABEL in the future. i.e. Administer / Content Types / edit(NODE) / Manage Fields / configure(FIELD) / and write NEWLABEL instead of LABEL. Then, I will also have to re-edit node-NODE.tpl.php file. It is bad practice to put the same information in two places since it makes maintainance difficult and error-prone. (In this case I put 'LABEL' both in somewhere in the database and hard-code it node-NODE.tpl.php too)
So could someone please tell me how to access the FIELD's label that resides in the database from the node-NODE.tpl.php file?
The closest page about could find about custom formatting custom fields http://drupal.org/node/62485, but the label is hard coded there too.
I use Drupal 5.2. I use Barlow theme (which uses PHPTemplate).
I hope I use the correct forum for my question.
Thanks
Ali
Comments
Contemplate and README
1. there is the contemplate module (http://drupal.org/project/contemplate) that can assist you with these things (not needed though but makes your life easier).
2. then there is a themes folder included in the CCK module that includes some examples and a README.txt file that should answer all your questions.
How can I have it both ways?
Thanks for the help. Somehow I had not noticed the modules/cck/theme directory. I still have a question though. In the README.txt file it says there are two basic options:
(i) theme individual fields, (create a field.field_FIELD.tpl.php file, in my example)
(ii) theme the whole body. (create a node-NODE.tpl.php file, in my example)
What I cannot see is how I can have it both ways. If I choose the first approach, the variable $label is available within field.field_FIELD.tpl.php file. But I want to theme the whole node. Then, all I have within node-NODE.tpl.php file is the variable $node->field_FIELD[0], which has ['value'], and ['view'] "records" but no ['label'] record for example.
I'd like to, either access to $label of my field like I did in field.field_FIELD.tpl.php file, or use the output of field.field_FIELD.tpl.php file within
my node-NODE.tpl.php file.
Thanks very much.
- Ali Tamur
I was pretty sure ['value'] would be the key
Really, I thought you could combine those two, create a field-field_yourfield.tpl.php and then the ['value'] of the field in node-yournode.tpl.php is populated with that. Obviously you need to have the phptemplate function that is provided in the cck/theme folder copied in your own template.php. But for some reasons this isn't working on my own sites, but I haven't updated to the most recent CCK version yet.
Maybe you should raise an issue for the CCK project, this would get the attention of the developer/maintainer.
Filed that issue to CCK project
I had the same problem (here), but did not receive a helpfull answer, so I asked again on the CCK project page How to print field labels.
possible patch
I believe the patch at http://drupal.org/node/209229#comment-886855 will resolve this issue for you by adding the label text to the data in the
$nodearray for your template, but it is a tentative solution. Please review/test the patch if you have this issue.