1

I'm customizing a view (in views-view--myview.tpl.php) based on a node which has a field with multiple value (field_galerie_image).

I'm trying to list in a foreach loop that particular field, and I am wondering how to write it down.

In the following code, I can access a value with $vue->_field_data["nid"]["entity"]->field_galerie_image['und'][0]["filename"]; but I need to loop through it.

$vue->_field_data["nid"]["entity"]->field_galerie_image['und'][1]["filename"];
$vue->_field_data["nid"]["entity"]->field_galerie_image['und'][2]["filename"];

The code I am using is the following one.

<?php foreach ($view->result as $id => $vue): ?>
  <?php if($vue): ?>  
    <?php print $vue->nid; ?>
    <?php print $vue->node_title; ?>

    <?php print $vue->_field_data["nid"]["entity"]->field_galerie_image['und'][0]["filename"]; ?>
  <?php endif; ?>
<?php endforeach; ?>    

1 Answer 1

-1

I found it out; the correct code is the following one.

<?php foreach ($view->result as $id => $vue): ?>
  <?php if($vue): ?>  
    <?php print $vue->nid; ?>
    <?php print $vue->node_title; ?>

    <?php foreach ($vue->_field_data["nid"]["entity"]->field_galerie_image['und'] as $val): ?>
      <?php print $val['filename']; ?>
    <?php endforeach; ?>
  <?php endif; ?>
<?php endforeach; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.