Reply to comment

How to add another formatter to a cck field? A cck formatter is basically a theming function where the value of field is ran through. Formatters are available at "admin/content/node-type/[your node type]/display" in the cck interface.

The previous screenshot shows your build modes of a node blog. Here you can change which formatter is used for which build mode. For example you might run the image through a different formatter in the full node than in the teaser. This screenshot is without the display suite. If possible you should use the display suite. It will make your theming life easier. You'll be able to define custom build modes too. Then it looks like this.

To add another formatter to the node displays you implement of hook theme. In our example we want to use a formatter for our title. The formatter will use the h3 tag to render our title.

<?php

/**
 * Implementation of hook_theme().
 */
function your_module_theme() {
  
$theme_functions = array();

  // Formatter theming functions.
  
$formatters = array(
    
'your_module_title_h3',
  );

  foreach ($formatters as $formatter) {
    
$theme_functions[$formatter] = array(
      
'arguments' => array('field' => NULL),
    );
  }
 
  return 
$theme_functions;
}

?>

Then you define your theme function

<?php

function theme_your_module_title_h3($field) {

  return '<h3>'.$field['object']->title.'</h3>';

}

?>

And in the final step you expose this formatter to cck using the hook_field_formatter_info()

<?php

/**
 * Implementation of hook_field_formatter_info(),.
 */
function your_module_field_formatter_info() {
    return array(
    
'your_module_title_h3' => array(
      
'label' => t('Renders text tru a h3 tag'),
      
'field types' => array('text'),
      
'multiple values' => CONTENT_HANDLE_MODULE,
    ),
  );
}

?>

Finally when you dont want to do all this in code (which you probably should because it is easier to control) there is a handy module called custom formatters

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><img><p><b><i><table><th><tr><td><blockquote><br /><img /><tbody><span><strike>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <codes>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.