I want to create a select list CCK field with multiple options. Then when the field prints, it would be assigned a set color. So for instance,

Age 0 to 2 (color: red)
Age 3 to 5 (color: blue)

The idea being that it would make posts easier to scan since patrons would be on the lookout for that colored field. Thanks!

Comments

Hanscraft’s picture

I tried using the steps offered by nevets in this example, but to no avail. I noted that the original poster listed that their content type is called info_about_me, but nevets has them calling the modified field-content.tpl.php to instead be: content-field-field_info_about_me.tpl.php.

In my problem, the content type is called cl_posts with the field_age_group. I have tried naming the modified field content-field-field_cl_posts.tpl.php and content-field-field_age_group.tpl.php and neither works.

Here is the information I posted in the modified tpl.php file:

<?php

/**
 * @file content-field.tpl.php
 * Default theme implementation to display the value of a field.
 *
 * Available variables:
 * - $node: The node object.
 * - $field: The field array.
 * - $items: An array of values for each item in the field array.
 * - $teaser: Whether this is displayed as a teaser.
 * - $page: Whether this is displayed as a page.
 * - $field_name: The field name.
 * - $field_type: The field type.
 * - $field_name_css: The css-compatible field name.
 * - $field_type_css: The css-compatible field type.
 * - $label: The item label.
 * - $label_display: Position of label display, inline, above, or hidden.
 * - $field_empty: Whether the field has any valid value.
 *
 * Each $item in $items contains:
 * - 'view' - the themed view for that item
 *
 * @see template_preprocess_content_field()
 */
?>

<?php if (!$field_empty) : ?>
<div class="field field-type-<?php print $field_type_css ?> field-<?php print $field_name_css ?>">
  <?php if ($label_display == 'above') : ?>
    <div class="field-label"><?php print t($label) ?>:&nbsp;</div>
  <?php endif;?>
  <div class="field-items">
    <?php $count = 1;
    foreach ($items as $delta => $item) :
      if (!$item['empty']) : ?>
              <div class="field-item <?php print ($count % 2 ? 'odd' : 'even') ?> <?php print $node->field_age_group[0]['safe']; ?>">
          <?php if ($label_display == 'inline') { ?>
            <div class="field-label-inline<?php print($delta ? '' : '-first')?>">
              <?php print t($label) ?>:&nbsp;</div>
          <?php } ?>
          <?php print $item['view'] ?>
        </div>
      <?php $count++;
      endif;
    endforeach;?>
  </div>
</div>
<?php endif; ?>

I modified my select_list to be color_name|Group One and then added these CSS classes to the stylesheet . I also made sure to clear my cache files and still no changes. Please help!

(I assume that a modified version of this could be used to call in image files instead of colors? )

drupalreggie’s picture

+ 1