Display custom field content in node.tpl i've a custom filefield in a custom content type and i use to display it in a node.tpl .But here my filefield has no limit number and under D6 i use this code :

    foreach($node-&gt;field_objectif_bts as $file) {
  if ($file['view']) {
      $header = array('data' =&gt; 'Les objectifs des formations BTS');
      $rows[] = array($file['view']);
      $attributes = array('id'=&gt; 'objectif-bts','sticky' =&gt; FALSE);
    }
}

$output = theme('table', $header,$rows, $attributes);
print $output;


In Drupal 7 it doesn't work, so I'm looking for modifications to do on this code or new code for Drupal 7 theming.

Actually, I tried the following.

foreach($node-&gt;field_objectif_bts as $file) {
  if ($file['und']['value']) {
      $header = array('data' =&gt; 'Les objectifs des formations BTS');
      $rows = array($file['und'][0]['value']);
      $attributes = array('id'=&gt; 'objectif-bts','sticky' =&gt; FALSE);
    }
}

$output = theme('table', array('header' =&gt; $header, 'rows'=&gt; $rows), $attributes);
print $output;


I also tried this code, but I get an error.

$w = entity_metadata_wrapper('node', $node);
foreach ($w-&gt;field_objectif_bts-&gt;getIterator() as $file_w) {
  // $file_w-&gt;file returns the wrapper of the File entity. You can
  // then address it's values as:
  $name = $file_w-&gt;file-&gt;name-&gt;value();
  $mime = $file_w-&gt;file-&gt;mime-&gt;value();
  $custom_field = $file_w-&gt;file-&gt;field_objectif_bts-&gt;value();
  // etc. You can see all available fields by inspecting the
  // return value of $file_w-&gt;file-&gt;getPropertyInfo()
  if ($custom_field) {
      $header = array('data' =&gt; 'Les objectifs des formations BTS');
      $rows = array($custom_field);
      $attributes = array('id'=&gt; 'objectif-bts','sticky' =&gt; FALSE);
    }
    $output = theme('table', array('header' =&gt; $header, 'rows'=&gt; $rows), $attributes);
print $output;
}


The error is the following:


  EntityMetadataWrapperException: Unknown data property field_objectif_bts. in EntityStructureWrapper->getPropertyInfo() (line 339 of /var/www/drupal7/sites/all/modules/entity/includes/entity.wrapper.inc).
There are two parts in your problem: one is getting the values, and the second is themeing them.

As far as getting the values is concerned, if you don't mind using the Entity and File Entity modules, a simpler way to access field content is to use entity metadata wrappers. This way you don't need to worry about deltas and languages.

You can write code as follows:

$w = entity_metadata_wrapper('node', $node);
foreach ($w-&gt;field_objectif_bts-&gt;getIterator() as $file_w) {
  // $file_w-&gt;file returns the wrapper of the File entity. You can
  // then address it's values as:
  $name = $file_w-&gt;file-&gt;name-&gt;value();
  $mime = $file_w-&gt;file-&gt;mime-&gt;value();
  $custom_field = $file_w-&gt;file-&gt;field_custom_field-&gt;value();
  // etc. You can see all available fields by inspecting the
  // return value of $file_w-&gt;file-&gt;getPropertyInfo()
}


As far as themeing the table goes, I think your call to theme is correct (If unsure, you can check the documentation for theme_table)