1

I need to change this tpl file which generate images for a image field to print the path to image instead of the image itself.

This code print out the images. It works fine

<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
  <?php if (!$label_hidden) : ?>
    <div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:&nbsp;</div>
  <?php endif; ?>
  <div class="field-items"<?php print $content_attributes; ?>>
    <?php foreach ($items as $delta => $item) : ?>
      <span class="<?php print $delta % 2 ? 'odd' : 'even'; ?>"><?php print render($item); ?></span>
    <?php endforeach; ?>
  </div>
</div>

I need to print just the path to the image (not the image). I tried with this code but I get a error message related to line 58. (see the error message below)

<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
  <?php if (!$label_hidden) : ?>
    <div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:&nbsp;</div>
  <?php endif; ?>
  <div class="field-items"<?php print $content_attributes; ?>>
    <?php foreach ($items as $delta => $item) : ?>
      <?php dpm($item); // I uploaded a capture of this dpm

          echo $item['#item']->uri; // THIS IS LINE 58

     ?>
    <?php endforeach; ?>
  </div>
</div>

Error:

Notice: Trying to get property of non-object en include() (line 58 de /Applications/MAMP/htdocs/lembassade.com/sites/all/themes/omega_subtheme_2/templates/field--field-im-genes-del-fondo.tpl.php).

enter image description here

1 Answer 1

2

From the looks of your devel output (and the error message), each $item is an array, not an object.

You should be able to fix it by changing the line inside the loop to:

echo $item['#item']['uri'];
0

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.