1

I'm trying to build a responsive gallery. Since views won't let me rewrite the field's output with html5 data attributes I need to print the output using a PHP field in views.

Using the module views_php, I'm accessing the values of the image field this way:

$source = $data->_field_data['nid']['entity']->my_field['und'][0]['filename'];

This way I load the value from the ['und'][0] array, this would work properly if a field has a single value. But what if in the node creation, in my field I want to upload multiple images. How could I change the [und] numerical value to load as many values as my field has.

Thanks in advance.

  • I think you should try a foreach loop. – Tyler Durden Aug 1 '12 at 8:58
2

As Syd said, it seems like you need a foreach loop. It's not readily apparent what you're wanting to do with the $source variable, but I'm guessing it's something like the following:

foreach ($data->_field_data['nid']['entity']->my_field['und'] as $a_file) {
    echo '<img src="' . $a_file['filename'] . '">';
}

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.