1
stdClass Object(
  [nid] => 98
  .......
  [title] => hello world!
  [body] =>
  ........
  [field_img] => Array(
    [0] => Array(
      [fid] => 200
      [list] => 1
      [data] => Array(
        [alt] => 
        [title] => 
      )

      [uid] => 1
      [filename] => coupon.jpg
      [filepath] => sites/default/files/coupon_0.jpg
      [filemime] => image/jpeg
      [filesize] => 4434
      [status] => 1
      [timestamp] => 1302080050
      [nid] => 98
      [view] =>  **the image**
      ......
    )
  )
)

Supposing the object is $test, echo $test->field_img[0]["timestamp"] in views-view-fields.tpl.php outputs 1302080050, but echo $test->field_img[0]["nid"] and echo $test->field_img[0]["view"] don't output anything; I can't print 98 and the image. print_r($test->field_img[0]) doesn't print the node ID and view? Why?

3

In Views template files you have access to the following objects:

  • $row
  • $fields['field_my_field_value']->row
  • $fields['field_my_file_value']->content

You do not have access to multiple image objects in your case. You should call an external function to retrieve data for each item.

$arg = (object) array(
  'type' => $fields['type']->raw,
  'vid' => $fields['vid']->raw,
);
$files = filefield_get_node_files($arg);

foreach ($files as $file) {
  print theme('imagecache', 'preview_body', $file['filepath']);
}
| improve this answer | |
  • how to use external function to retrieve data for each item.could you make me an example? thank you – enjoylife Apr 7 '11 at 4:45

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.