CCK is a great module for allowing use to create custom content types without having to write a node module. Out of the box CCK provides everything a user would want. But there are times where I need to do some custom queries or add a custom theme function to get things just right. So here's something I like to do to keep things well and organized. The best way to do this would be to copy the content-field.tpl.php from the CCK theme directory into your own theme directory. This will target ALL fields, but you'd like to modify onlt that one text field in that one content type. Well, you'd start off again by moving the content-field.tpl.php to your theme directory, and then create a copy of this file with the following schema:

content-field-FIELD_NAME-NODE_TYPE.tpl.php

If you'd like to modify a field that spans across multiple content types, you could use the following naming convention:

content-field-FIELD_NAME.tpl.php

I usually have a module for each custom content type if there is to be extra functionality to be implemented. So what I like to do is implement the following in my module:

function hook_theme_registry_alter($themes) {   $module_path = MODULE_PATH   $themes['content_field']['theme paths'][] = $module_path; }

The above code will suggest different paths of where template files may reside for the given theme function. From here, you can follow the same steps of copying content-field.tpl.php to your path and you'll be able to override the theme of the CCK field. You probably could even add preprocess functions if you wanted to do preprocess the field. This sort of implementation allows us to override the output of a single field. This also makes it so that we're not dependent on the theme and that our content type fields will be themed exactly the way we need it no matter which theme we use. There are probably pros and cons about this implementation, so feel free to share your ideas or thoughts.

The interweb my ~ away from ~

Read Next
Appnovation Blog Default Header

Proximity Search using Views in Drupal

10 February, 2010|3 min