Theming fields in Drupal 6
I needed to figure out how to theme a field in Drupal 6. The use case was that I wanted to field to be a URL. This is pretty simple and straightforward by using the CCK Link module, which is a sub-module of CCK.
I was able to input my URL, such as http://www.symetrikdesign.com with no problem, and the CCK display options are pretty good. However, I wanted to strip the “http://” part on the output display, but have the link remain the legitimate link of http://www.symetrikdesign.com
Though, there are several options for outputting the display in the Admin/Content Type/
So I figured that I needed to theme the custom field. I searched drupal.org and google.com far and wide and found that though the documentation was present, there wasn’t much of it and it wasn’t that clear.
Here’s what I did.
My field name was called artistwebsite, so I needed to make sure that there was a standard content-field.tpl.php in my theme’s directory and then copy/clone that and call the new file content-field-field_artistwebsite.tpl.php. This works like other types of Drupal entity template files, but the tricky part is that you need to find content-field.tpl.php into your theme’s directory, because it probably isn’t there by default, depending on your theme.
I now have the following in my theme directory, and a field called field_artistwebsite in my content type.
content-field.tpl.php
content-field-field_artistwebsite.tpl.php
I was able to re-write the output of a CCK Link field so that it removes the “http://” on the display title on the node.
I did this by adding the following lines of code in place of the commented out print statement below:
".$item['display_title'].""; /* Here is the original PHP print statement line in the stock/default content-field.tpl.php * file that I commented out and replaced with what is above. * */ ?>