I've found several posts dealing with this issue, mostly focused on removing the colon if the label end with a "?".
http://jaspan.com/removing-unwanted-colons-form-field-titles
http://www.lullabot.com/articles/what_if_a_field_title_ends_with_a_quest...

And I found this page - http://drupal.org/node/293908 - that provides a template.tpl.php function for removing the colon from all labels (which btw, didn't work for me).
Has anybody figured out a way to customize the colon display based on the content type?
I thought it would be easy, but after several hours, I still haven't gotten anywhere.

thanks

Comments

maryannking’s picture

I have tried all of the references you gave above and none of them have worked for me. I am using drupal 6 with a modified frameworks theme .

Did you ever come up with a solution?

ipswitch’s picture

this seems so simple. sure it's usually nice to have the colon but when you don't need it, it seems to be impossible to hide. If I find a solution, I will post it here.

decibel.places’s picture

I tried the the function meier_form_element method http://drupal.org/node/293908 but it does not remove the colons on the webform

I created a custom theme named "meier" from framework too, and renamed the theme directory and info file and info file info:

; $Id: framework.info,v 1.1.4.2 2008/11/28 06:14:30 andregriffin Exp $

name = meier
description = based upon Framework theme
core = 6.x
engine = phptemplate
stylesheets[all][] = style.css
stylesheets[print][] = print.css
stylesheets[all][] = meier.css

; Information added by drupal.org packaging script on 2008-11-28
;version = "6.x-2.2"
;core = "6.x"
;project = "framework"
;datestamp = "1227853513

and the function phptemplate_form_element() method http://jaspan.com/removing-unwanted-colons-form-field-titles does not work either

the only way I can remove the colons is by hacking the core, includes/form.inc and removing the colons from $t('!title: to make them $t('!title in function theme_form_element lines 2202 and 2205

I tried copying this exact function to the template.php in my theme and renaming it meier_form_element and no luck :(

ipswitch’s picture

save the below code as "content-field.tpl.php" and drop it in your theme folder. Works for me and no need to hack core.

<?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 if ($label_display == 'inline') { ?>
            <div class="field-label-inline<?php print($delta ? '' : '-first')?>">
              <?php print t($label) ?></div>
          <?php } ?>
          <?php print $item['view'] ?>
        </div>
      <?php $count++;
      endif;
    endforeach;?>
  </div>
</div>
<?php endif; ?>

decibel.places’s picture

I created the file and put it in my theme - which is a custom adaptation of the framework theme

I also replaced the hacked includes/form.inc with a fresh copy

nothing happened

I tried including "content-field.tpl.php" in the theme template file and got an error:

warning: Invalid argument supplied for foreach() in /home/decibelp/public_html/meier/sites/all/themes/meier/content-field.tpl.php on line 15.

I think it is because the code provided is designed to remove the colon from content-fields but not from form fields

So when I upgraded to core 6.11 I lost my hacked form.inc file

I devised a DHTML method to remove the colons from webform labels http://drupal.org/node/293908/1540580

RobertPope’s picture

I like this because it leaves in the colon wherever it is supposed to be, but if for example I end a field with a ? it removes the colon on the fly so I don't end up with a ?: and I don't have to remember to add colons everywhere because I removed them entirely (but should I forget the script is smart enough to know I don't want a :: - comes in handy
If you want to make it smarter just expand the switch statement. -peace (don't forget to rename the 'theme' with your theme or you will get errors!

This copy paste this code at the end of your template.php file in your theme's directory

/**
* Intelligent Lables - removes the ':' after lables if the field ends with punctuation so you don't see things like '?:' on our forms 
* Do not forget to rename the function from 'theme_form_element' function to 'yourtheme_form_element'!!!
*/

function theme_form_element($element, $value) {
  // This is also used in the installer, pre-database setup.
  $t = get_t();
  
  
  // Get the last character of a string - needed to determine if the last character is punctuation or not.
  $str = $element['#title'];
  $last = $str[strlen($str)-1];
  switch ($last){
    case "?":
      $pun = " ";
      break;
    case ":":
      $pun = " ";
      break;
    case ".":
      $pun = " ";
      break;
    default:
      $pun = ":";
   }
  $output = '<div class="form-item"';
  if (!empty($element['#id'])) {
    $output .= ' id="'. $element['#id'] .'-wrapper"';
  }
  $output .= ">\n";
  $required = !empty($element['#required']) ? '<span class="form-required" title="'. $t('This field is required.') .'">*</span>' : '';

  if (!empty($element['#title'])) {
    $title = $element['#title'];
    if (!empty($element['#id'])) {
      $output .= ' <label for="'. $element['#id'] .'">'. $t('!title'. $pun .'!required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
    }
    else {
      $output .= ' <label>'. $t('!title !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
    }
  }

  $output .= " $value\n";

  if (!empty($element['#description'])) {
    $output .= ' <div class="description">'. $element['#description'] ."</div>\n";
  }

  $output .= "</div>\n";

  return $output;
}
decibel.places’s picture

this looks like a good approach, with nice flexibility

you need to remember to re-add it to your template if you update the theme to a new version

using DHTML code in a block does not get affected by an update

like most things on computers, there are many ways to do this

also, because I suffer from "pforp": I want to point out that "label" is spelled with an "el" (however "ladle" is not)

RobertPope’s picture

yeah - that english get pretty tricky sometime :)

akalata’s picture

:)

Sinan Erdem’s picture

Thank you for the code. Works for me...

syntheticMedia’s picture

Im getting a fatal error when using in my zen template.php, any suggestions?

nkraft’s picture

That worked great for me, thanks for the info!

iantresman’s picture

This simple solution suggested by iko worked for me. In Views | Fields:

  1. set Label to "none"
  2. rewrite the field with you own label, eg.
    mylabel... [field_my_cck_field_name_token]
tlangston’s picture

Copied the field.tpl into my custom template directory. Removed the colon from the label definition:

from
php print $label ?>:

to
php print $label ?>

Couldn't have been any easier.

Liam_Mc’s picture

Simple and effective, thanks.

symphonia’s picture

Hi, I've made the same thing: removed the colon from the label definition, and then copied field.tpl into themes/templates directory but it didn't work...
I think I've missed something...

ptitwolfy’s picture

Just give a try to the No Colons module, worked perfectly for me:
http://drupal.org/project/no_colons

idmloco’s picture

This solution works if the field was created by CCK. Using Drupal 6.28 and CCK 2.9

Copied /sites/all/modules/cck/theme/content-field.tpl.php into my theme folder, /sites/all/themes/[theme-name]/content-field.tpl.php

Edited the content-field.tpl.php in my theme folder, Removed the colon from line 31 & 40

If you only want to remove the colon on specific fields you can do this:
Copy the content-field.tpl.php into your theme folder
Duplicate content-field.tpl.php and rename this one: content-field-[field_name].tpl.php, ex. content-field-field_project.tpl.php
- make sure to have both files in your theme folder or it wont work.

Reference: http://drupal.org/node/269319