Site Network:

Theming CCK - presentation and materials

Learn about theming CCK fields

1/05/2009 - Doing this in Drupal 6 instead of D5

For DrupalDaze, I started putting together some materials for learning about theming CCK fields.

Here it is...

Note
Basically, you will be downloading and making a drupal installation that already has some content types, gross-looking themes (for you to improve), and content. You will see that some good modules are turned on. Some views are also set up.

Please leave comments on anything that is too confusing and I will try, over the next few months, to improve this into a more helpful theming training piece.

Presentation

Experimental presentation: http://docs.google.com/Presentation?id=dgr8r28w_39fsrk76ch
(Note, I am very interested in pursuing this idea of communicating the structure of drupal's backend through cute monsters, in cartoons)

The presentation describes my process for thinking about how to structure fields, build them into drupal as CCK types - and then gives some idea of why certain syntax is used to theme CCK in Drupal 5.8.

Field templating methods

1. organize fields (CCK gui 'manage fields')
2. set up field labels and descriptions
3. fix up display of fields (CCK gui 'display')

method 1: theme individual fields

  • add phptemplate_field to template.php
  • drop field-myfield.tpl.php into your theme folder

method 2: theme individual nodes

  • drop node-mycontenttype.tpl.php into your theme folder (include $teaser conditional to display custom teasers)

method 3: use Contemplate GUI (set up fields, SUBMIT for body and teaser)
method 4: split out Contemplate templates into files and upload to
sites>all>contemplates node-mycontenttype-body.tpl.php, node-mycontenttype-teaser.tpl.php, node-mycontenttype-rss.tpl.php
method 5: make customized template handling modules.
example, contemplate_lite - let me put body & teaser templates in theme folder, and makes it possible to make other theme files

Downloads

There is a website up and running that shows some theming of fields
http://food.artmess.org

But more important than that site - I've set up a whole drupal installation for anyone who wants a head start...getting to the point of having all the parts in place in drupal - which you need in order to theme it - takes a bit of work.

Attached to this document:
Download the DB: field_themes_demo_db.sql (zipped)
Download sites>all folder: food_drupal_site_all.zip, Drupal 5.8

I haven't tested this, but to install it you would probably need to:

  • be able to create new databases and run mysql scripts (or make someone do it for you)
  • be able to save files into your drupal installation
  • for the theming of the files, you will need to write some php code
  1. download the files (attached at the bottom of this document)
  2. unzip those files on your computer
  3. make a new drupal 5.8 installation
  4. copy themes/contemplates/modules into the sites/all folder in your drupal installation
  5. make a new database called: field_themes_demo_db
  6. run something like this to import the database from the command line:
    mysql -u username -p -h hostname field_themes_demo_db < field_themes_demo_db.sql
  7. change your sites>default>settings.php -- to point to field_themes_demo_db with the appropriate permissions and $base_url

6. If all goes well, you should have a working version of the food sample drupal installation, and you can mess with all the different methods of theming content. Also, you can use this as a recipe book for yourself.

7. These are the modules used:
cck
cck_address
computed_field
contemplate*
contemplate_lite* (not an official contributed module, but instead one that I made)
content_utility
date
devel
image
image_api
imagecache
imagefield
image_assist
pathauto
token
views

* Have just one of these modules turned on at a time.
Contemplate uses the sites/contemplate folder, contemplate_lite uses folders in the theme.

Hidden Easter Eggs in the folders

You'll see an example of a themed input form - the syntax for theming that form is totally different. Look in the template.php file for the theme and you'll see some code that turns on the ability to read the contemplate_lite_forms

One day, I would really like to learn how to break the themed forms into multiple steps. This is supposed to be much easier in Drupal 6. I would like to do this with jQuery/anchors -- but the important part is that you submit data along the way.

I have themed views nodes/lists. When I get a chance, I'll add some of that information. I view this example as a work in progress, but I only have time to work on it every few weeks.

Some resources for learning about theming CCK fields

Content Construction Kit Handbook: http://drupal.org/node/101723
CCK for Themers: http://drupal.org/node/62462
Theming CCK the Agaric Way: http://agaricdesign.com/theming-cck-the-agaric-way
Drupal 6 Screencasts - Views 2, CCK 2, Panels 2: http://www.topnotchthemes.com/blog/080727/drupal-6-screencasts-views-2-c...
Theming a CCK Node: http://www.alldrupalthemes.com/blog/theming-cck-node.html
Theming CCK Input Form: http://drupal.org/node/187239
How to theme a CCK input form: http://drupal.org/node/101092

Theming differences between Drupal 5.8 and Drupal 6

I haven't actually themed anything with drupal 6 yet, aside from using contemplate very hastily on some content types.

But, I have heard that theming is very different in Drupl 6 -- seems like theres a new way to theme views output - which sounds great to me, because as I work I notice that I need lots of different kinds of teaser output, and usually just 1 node type.

So what's the best way to approach theming fields?

  • I hope to figure this out.
  • Personally, I really prefer working with template files for my themes.
  • It's easiest to start learning how to theme fields if you start with contemplate.
  • Seems to me like an important part of making drupal truly usable has everything to do with theming cck fields and input forms. Drupal is great for handling the content...but if it's better to get units of contents into fields -- then giving end-users a nice flow for adding in their information is really important. So many larger sites have developed conventions for this...but drupal is still pretty slow to theme if you are dealing with lots of fields and lots of content.