0

We have a content type displaying taxonomy term input as one of its fields. The goal is to display the one or more terms as an unordered list. That is not an option available in the Manage Display tab, and the default display does not break the entries into separate lines:

default display of taxo terms

Editing the theme's template.php file by changing

$output .= ($variables['element']['#label_display'] == 'inline') ? 
'<ul  class="links inline">' : '<ul class="links">'; 

to

$output .= ($variables['element']['#label_display'] == 'inline') ? 
'<ul class="links inline">' : '<ul class="list">'; 

we get the desired bulleted list:

display from modified template.php

– but that is not desired as the default in other content types.

How can this display be customized to be unique to this content type? From some reading it is understood that a custom field tpl.php could do this, but help is needed in understanding how to set that up for this unique situation. Can anyone suggest a path?

--Thanks--

0

Use template_preprocess_field()

You can try something like this in your template.php:

/**
 * Implements template_preprocess_field().
 */
function YOURTHEMENAME_preprocess_field(&$variables, $hook) {
  if ($variables['element']['#object']->type == 'YOUR_CONTENT_TYPE_NAME') {
    $output = '';

    // Render the label, if it's not hidden.
    if (!$variables['label_hidden']) {
      $output .= '<h3 class="field-label">' . $variables['label'] . ': </h3>';
    }

    // Render the items.
    $output .= ($variables['element']['#label_display'] == 'inline') ? '<ul class="links inline">' : '<ul class="list">';
    foreach ($variables['items'] as $delta => $item) {
      $output .= '<li class="taxonomy-term-reference-' . $delta . '"' . $variables['item_attributes'][$delta] . '>' . drupal_render($item) . '</li>';
    }
    $output .= '</ul>';

    // Render the top-level DIV.
    $output = '<div class="' . $variables['classes'] . (!in_array('clearfix', $variables['classes_array']) ? ' clearfix' : '') . '"' . $variables['attributes'] .'>' . $output . '</div>';

    return $output;
  }
}

Once implemented, try flushing you theme cache, it should work.

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.