Can anyone advise me on how to change a cck field's label via the preprocess_node function? I'm trying to change the label for one field based on the values of some other fields.
In my theme's template.php theme_preprocess_node function I've tried something like the following (based on a search through print_r($vars);):
if ($vars['template_files'][0] == 'node-inventory') {
$vars["node"]->content["field_inventory_price"]["field"]["#title"] = "Test Price:";
}
It looks like this field gets changed back after this, or the theming and conversion to html for this field happens before the preprocess_node function hits it. Is there another place I should be setting this?
Comments
Comment #1
markus_petrux commentedIf you implement MODULE_preprocess_node(), changes are available to node.tpl.php, but that takes effect only if you plan to render CCK fields in your node templates manually.
On the other hand, you could implement MODULE_preprocess_content_field(), and that should affect content-field.tpl.php and variants, which is different than node.tpl.php.
Comment #2
jacobkdavis commentedMODULE_preprocess_content_field() is exactly what I was looking for, thanks!
For posterity, in case anyone else is interested in the future, the code to change a field's label (similar to the non-working code above) would be: