8

The Views module has the nice option to rewrite the output of a field. This allows to adapt the output of CCK fields using Tokens without having to create a template for that view.

Is there a module that would allow a similar functionality for the "Display Fields" tab of a content type? I need to slightly modify the field output for teaser and body, but don't want to create a full template.

I'm currently using Contemplate for that, but that is more complicated than I need and unnecessary difficult if you're not familiar with the Drupal PHP API. It is also annoying that I need to modify the template every time I add an additional field to the content type, I really only need to rewrite a few fields, not the whole body or teaser.

So, what I would like to have is a simple way to rewrite each CCK field output using any token available for that content type. Does something like that exist?

5

Sounds like you're looking for the Custom Formatters module, very similar to Contemplate, but specifically for create Field Formatters to be used via the Display Settings page or Views.

Custom Formatters can be built with both Tokens or pure PHP code.

Additionally, Custom Formatters can be exported as native Drupal Hooks or in a custom Features exportable format.

4

If you're just looking to tweak the markup, Semantic CCK is worth a try.

Semantic CCK was created to give users the means of customizing the HTML output of CCK fields. It was inspired in part by the highly recommended module Semantic Views which provides the same functionality for Views.

Drupal 7

A Drupal 7 version of Semantic CCK is currently under development: Semantic Fields.

2

Using the Contemplate module is not recommended since it puts PHP code into the database which is generally considered a security vulnerability and non-performant.

You may consider defining your own field formatters using hook_field_formatter_info(). This allows you to define custom callbacks that can handle each field. Here's a simple tutorial on how this works for Drupal 6.

Browse other modules' implementation of hook_field_formatter_info() to see how it works. In Drupal 6 it ties in directly with hook_theme() while Drupal 7 uses hook_field_formatter_view().

0

You might be looking for the Display Suite module which will give you the most control of formatting in D6. Here is a demonstration video.

0

I've been fighting with this same issue for some time now too.

I can't / don't want to use...

  1. Contemplate for mediocre architecture reasons.
  2. Display Suite, which is awesome but overkill and doesn't actually allow simple alterations to fields.
  3. Custom formatters, as it again ends up with PHP in the database for multiple value fields.
  4. Field template because I'm just adding a line of text with the item.
  5. Semantic CCK because that only alters the elements and classes.
  6. hook_preprocess or another code based solutions because I need it configurable.

It's a real bummer, when all I need to do is add a CCK field description to display output. This should actually be rather simple.

Sounds like you needed Custom Formatters.

  • n/m this functionality was added to Semantic CCK 1.4 – doublejosh Jun 2 '11 at 9:56
  • did you find a easy to handle solution that has a good performance? in drupal6 the good solution was often to use the ['view'] of the node object and combine it with some node template formatting. very clean output and comfortable because of the use of ['view'] in 90% of all use cases. in drupal 7 we have again the divities, because render() produces a lot of overhead ... – user1649 Jun 16 '11 at 8:33
  • Sounds like Display Suite then drupal.org/project/ds – doublejosh Jun 17 '11 at 7:27
  • Custom Formatters does store information in the database, but the module is simply a utility, so once you've created the Formatter in the database you export it and you no longer have the issue of code in the database :) – Decipher Jun 26 '11 at 22:49
0

The Token Field module lets you combine fields using their tokens.

0

This is a very quick and clear explanation of custom formatters for D6:

http://manueg.okkernoot.net/blog/200907/how-create-cck-formatter

0

I would use the Token Filter module, to specify token values in CCK fields with input filters. Here is an excerpt about it from the module's project page:

... a very simple module to make token values available as an input filter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.