Hi,

in my special case, users are allowed to choose multiple values from a long, very long, vocabulary list.
When displaying the fields, each term is in its own line. Is there an easy way to make this list comma seperated?

Thanks for any help

rainer

Comments

mh86’s picture

Status: Active » Fixed

Hi!
yes, if you want your own theming, you have to override the default in a template file.

korayal’s picture

another possible solution;

http://drupal.org/node/167255

Anonymous’s picture

Status: Fixed » Closed (fixed)
blecheimer’s picture

override in template.php (Drupal 6, actual version of content taxonomy)

/**
 * OVERRIDE Theme function for 'default' text field formatter.
 */
function yourthemename_content_taxonomy_formatter_default($element) {
  if (!empty($element['#item']['value'])) {
    $term = taxonomy_get_term($element['#item']['value']);
    _content_taxonomy_localize_term($term);
    $custom_content_tax = check_plain($term->name).'<span class="custom_comma_seperated">, </span>';
    return $custom_content_tax;
  }
}

now, you will get a comma after every term.

To do not display the last comma => add this to your css file: (I am not a php coder- i don't know another way, but there is one)

.field-type-content-taxonomy .field-item:last-child .custom_comma_seperated {
    display:none;} 
abaddon’s picture

this applies to latest drupal 6 as of today, ive just copied the function from the module and added the $last variable and used it in the return

/**
 * Theme function for 'link' text field formatter.
 */
function SITETHEMENAMEHERE_content_taxonomy_formatter_link($element) {
  if (!empty($element['#item']['value'])) {
    $last = $element['#item']['#delta'] + 1 == count($element['#node']->$element['#field_name']);
    $term = taxonomy_get_term($element['#item']['value']);
    _content_taxonomy_localize_term($term);
    return l($term->name, taxonomy_term_path($term), array('attributes' => array('rel' => 'tag', 'title' => $term->description))) . ($last ? '' : ', ');
  }
}

p.s. handles not placing a comma for the 'last' element, this is a theme override in template.php, use it from your custom theme..

trevorjfitz’s picture

Looks great, seems great, great idea, but....I can't get it to work. Bah! Can the $last variable really used in this context?

trevorjfitz’s picture

Status: Closed (fixed) » Active

Ok, I realize now that my previous comment may not have made much sense.

If I print the code count($element['#node']->$element['#field_name']); I get 0's for every element. And when I print_r($element) I wonder how count could be useful, since it is one of everything.

I'm depressed I have spent so long on this issue, but it isn't an optional requirement for me. Ah the life of a developer.

summit’s picture

Version: 4.7.x-1.x-dev » 6.x-1.x-dev

Subscribe and set do D6, which is where the last comments are about. How to get a bullit list of terms?
greetings, Martijn

trevorjfitz’s picture

Well, I officially have the lamest solution ever to this problem.

Step 1:
In the PHP from step 5, add a span with class "commaKiller"

    return check_plain($term->name) . '<span class="commaKiller">' . ($last ? '' : ', ') . '</span>';

Step 2:
Just before the end of the body tag in page.tpl.php, include the following code:

<script type="text/javascript">
	/* Comma Killer */
	$(".field-content .field-item:last-child .commaKiller").css("display","none");
</script>

There you have it. It works!

abaddon’s picture

@trevorjfitz - you are using this from template.php in the site's active frontend theme right? not in a module
last time i used this (when i posted it) it worked fine.. maybe content taxonomy changed something in its theme_ function..
$last is a boolean deciding if this is the last printed element, i dont remember why it looks so cthulhian but it should make sense if you var_dump stuff there and content taxonomy DIDNT change something.. ->$element['#field_name'] is evaluated to a string like ->($[..]) http://php.net/manual/en/language.operators.precedence.php