On meaningful CCK field names

2008-01-24 / jpoesen

The CCK module lets you add custom fields to any node type in Drupal. The views module is an advanced visual query builder that lets you define lists of nodes.

When you create a view, you need to define which fields (also known as columns) should be shown. You do this by choosing the field in a drop down list. However, if you have, say, 5 content types and you defined, say, 10 fields for each content type, your dropdown will contain at least 50 fields (+ the standard, non-changeable node fields). Needless to say, you can spend a very long time finding the correct fields if they were not named in a meaningful way.

So, please, pretty please with sugar on top:

- use a descriptive name (‘phone’ rather than ‘f12’)

- prefix your field names with the content type (product_name, event_startdate, ...)

- but don’t prefix them with ‘field_’ since they’re automatically prefixed that way. You don’t want to end up with ‘field_field_country’

- be smart, but be lazy. Descriptive is good. Short is also good. Remember that CCK field names are reused by Drupal to construct appropriate css classess in the output, and chances are you’ll be writing css that refers to those classes, so keep it short.

- be consistent