Play

Theming a Specific CCK Field

Jocelyn
Post to Twitter

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...

Add comment

  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags
  • Websites and email addresses turn into links automatically
  • Use one of the forms name.module, name.theme, name.translation, name.installprofile or name.project, in order to link to http://drupal.org/project/name. Note that a link will be generated even if a project does not exist
  • Lines and paragraphs break automatically
Your email will not be displayed publicly. If you have a Gravatar account, used to display your avatar.

jsfwd on Twitter 

  • BIXI debuts bike sharing program in Toronto http://bit.ly/cTruQl 1 day 21 hours ago
  • Vote #Toronto to host DrupalCon 2012 North America http://bit.ly/aXgBkJ 3 days 19 hours ago
  • Toronto #Drupal meetup tonight 6:30pm @CSI http://bit.ly/cGL63w 4 days 19 hours ago
  • Display a Twitter Profile using YQL & jQuery http://bit.ly/ajAfu6 5 days 21 hours ago
  • Google Images got a facelift.... size, type & colour filters... pagers gone... wow! 1 week 2 days ago
  • Wouldn't that just be Drupal? RT @becircle: I just heard the words I feared I might hear some day "They created a GUI for Drush" #drupal 1 week 3 days ago
  • #Raptors acquire Leandro Barbosa... w00t w00t!! 2 weeks 5 days ago
  • The NBA is a whole lot less interesting today. 3 weeks 22 hours ago
  • Site Aliases, Groups and Remote Capabilities! RT @lwalk: New features in Drush 3 http://bit.ly/aIzmxw #drush #drupal 4 weeks 2 days ago
  • Twitter delays the OAuthcalypse another 6 weeks http://countdowntooauth.com 4 weeks 3 days ago
@jsfwd on Twitter »
i heart Drupal