Theming a Specific CCK Field

Jocelyn's picture
Tags:

The display of CCK fields is handled by the file content-field.tpl.php which is in the folder sites/all/modules/cck/theme. To override the display of a specific CCK field, the system will look for the format content-field-field_name.tpl.php in your theme directory.

Assuming you have a field named 'files', the name of your override would be content-field-field_files.tpl.php. If you're not sure of the field name go to admin/content/types and select the Fields tab - which will give you an overview of all your CCK fields.

Unlike adding theme overrides for modules like Views where you can override views-view.tpl.php in your theme by simply adding a new tpl file views-view--frontpage.tpl.php, CCK needs you to also place the base tpl file you're overriding - even if you're not making any changes. If you don't have this *base* tpl file also included in your theme directory, your specific CCK field override will not work.

Steps

  1. Copy content-field.tpl.php from sites/all/modules/cck/theme to your theme directory.
  2. Make a copy of content-field.tpl.php and rename it content-field-field_name.tpl.php
  3. Update your theme registry
    • Admin Menu: From the favicon dropown select Flush all caches > Theme registry
    • Visit your theme page at admin/build/themes
  4. Make your custom changes to content-field-field_name.tpl.php

Tip

When you override tpl files in your theme, it's not necessary to place them in the root folder of your theme - which can make your theme messy real quick. You could create a tpl folder within your theme to house all your tpl overrides. You could also create subfolders within this tpl folder for each module you're overriding, ex./cck, views, webform etc...

Tags:

Comments

Anonymous's picture

Thanks for step 3, had done this before and forgot this step.. have been pulling my hair out trying to figure out why it was not working this time.

Anonymous's picture

Great post and I have managed to do so following your steps. is there a chance you can post example of how to layout multiple fields within a node to create a table like feel for the fields. can we control example content-field-field_phone.tpl.php with the 960.gs system
Thank you for your time on this.
JOe

Add New Comment