Theming a Specific CCK Field in Drupal

The display of CCK fields is handled by the file content-field.tpl.php which is in the foldersites/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 theFields 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 dropdown 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

 

Original posted here http://ninjagirl.com/posts/007/theming-specific-cck-field

Wiki Tags: 

Testimonials

With people from HalfPixel we always found best solution, for clients and for us.

Peter Potocar, BIgKids.sk

Are you around here?

When you`re not far, come visit us.

Contact