Right now the field is template is:

<div class="field-name">
   <div class="label">Label</div>
   Field Content
</div>

I would however like to be able to theme the field content in a different way, and I need the field content itself to have a wrapper.

So please make the theme like this:

<div class="field-name">
   <div class="label">Label</div>
   <div class="field-name-content">Field Content</div>
</div>

Comments

swentel’s picture

Status: Active » Closed (works as designed)

After a few discussions with some theming people and looking at the way cck handles its field theming, it's probably more interesting to keep it the default way. However you can override the ds_field theming function with phptemplate, a bit like this:

function phptemplate_ds_field($content, $field_key, $field) {

  $output = '';
  if (!empty($content)) {
    if ($field['type'] == 'ds') {
      $output .= '<div class="field field-'. $field_key .'">';
      // Above label.
      if ($field['labelformat'] == 'above') {
        $output .= '<div class="field-label">'. $field['title'] .': </div>';
      }
      // Inline label
      if ($field['labelformat'] == 'inline') {
        $output .= '<div class="field-label-inline-first">'. $field['title'] .': </div>';
      }
      $output .= '<div class="field-'. $field-key .'-content">'. $content .'</div>;
      $output .= '</div>';
    }
    else {
      $output = $content;
    }
  }

  return $output;
}

Hope that's ok with you ?

ManyNancy’s picture

Yes, thank you for your help. :)

ManyNancy’s picture

Hi, there seems to be some problems with the function you showed me.

function phptemplate_ds_field($content, $field_key, $field) {

  $output = '';
  if (!empty($content)) {
    if ($field['type'] == 'ds') {
      $output .= '<div class="field field-'. $field_key .'">';
      // Above label.
      if ($field['labelformat'] == 'above') {
        $output .= '<div class="field-label">'. $field['title'] .': </div>';
      }
      // Inline label
      if ($field['labelformat'] == 'inline') {
        $output .= '<div class="field-label-inline-first">'. $field['title'] .': </div>';
      }
      $output .= '<div class="field-'. $field_key .'-content">'. $content .'</div>';
      $output .= '</div>';
    }
    else {
      $output = $content;
    }
  }

  return $output;
}

Here's the function, plus a couple of typo fixes. But it's still no good. The HTML is screwy, like it's missing a close div or something. I also don't see the content wrapper for some reason... Any clue what's going on? Thanks.

swentel’s picture

Works perfectly on my end here - with 6.x.1-0 release - if you happen to run with a later dev version, than it's normal because the parameters have changed in that theming function.
I just pasted this in my template.php and cleared the cache so theme registry picked it up.