I have a custom node type I created with CCK that uses image field. I have teaser and node views set up with a custom content template. Both of these views are working correctly.

I recently created a new block view, set the view type to list and added the image field to the Fields list. I used the Theme Wizard, added a function to my theme template.php file, and created a views-list-[viewname].tpl.php file.

Within the tpl.php file I have a line of code: <?php print $field_image_fid; ?>
which returns something like <img src="path_to_image" />

I'm trying to create a link around this image and am banging my head against a wall. I'd like to get the path to the image and the image file name and have calling:
$node->field_image[0]['filename']
...but this returns nothing. I've tried print_r($node) and there's nothing I want in the array. I'm probably being stoopid but for the life of me I cant remember/figure out how to access the "real" array of node info from within this block. I call $node->field_image in my teaser and body templates just fine...

Any suggestions? Thanks,
pp

[Edited to add <code> and </code> tags; nevets]

Comments

nevets’s picture

Using image field 5.x-2.0-rc6, image cache 5.x-2.0-beta and views 5.x-1.6 when I add an image field to views (as a field) under options I have a drop down that for each image cache type allows me to show the image as an unlinked image, image linked to node or image linked to full size image.

ppmax’s picture

Yep--I have my image field set up correctly: I already have a teaser and body views templates. What I'm trying to do is access the image field values within a custom list view.

For example: the object "$field_image_fid" provided by the Theme Wizard outputs something like:
img src="path_to_file"...

What I want is to call something like:
$node->field_image[0]['filename'] within my views-list.tpl.php file that will output the string value of the image name....

ppmax’s picture

Thanks for adding those nevets. I realized after I posted that I forgot them and couldn't edit my original post.

devink’s picture

I have the same issue, have you had any luck? The filename is populated for me, but still returns blank when queried...

<div class="view-field view-data-field-photo-fid">
<?php print $field_photo_filepath ?>
Staff Photo
</div>
<div class="view-field view-data-field-photo-fid">
Staff Photo
</div>

All the best,

Steve V

devink’s picture

I used Contemplate as a method of getting to the relevant field names and PHP code.

print $field_photo_filepath

should be

print "<img src='/" . $node->field_photo[0]['filepath'] . "'</img>"

All the best,

Steve V

DesignICU’s picture

Having the same issue. Desperate to get to the img path inside $field_image_fid.

Tried devink's solution, with Contemplate, but still no joy.

DesignICU’s picture

1) In your file, use...

print "<pre>"; print_r($node); print "</pre>";

...to get a list of the incoming fields, then...

2) You can use something like...

print "<strong>File Name:</strong> ".$node->node_data_field_image_field_image_alt;

...to grab the file name.

HTH,

Sean

ppmax’s picture

Thanks for the reply. I've tried all these things but they don't work inside a block view. Doing:
print_r($node);
inside my block view returns:
stdClass Object ( [nid] => 57 [random_sort] => 0.000761895441228426 [node_data_field_image_field_image_fid] => 35 [node_data_field_image_field_image_title] => [node_data_field_image_field_image_alt] => [files_filename] => [files_filepath] => )

As you can see there are no values for any of the array elements that you'd think would give me what I want. OTHO, the block view does return the node ID, but I havent figured out how to return all the properties for a give node ID.

Any tips?

Thanks again

UnicornSong’s picture

I too have this issue
I am trying to customise a view to have a cck imagefield image open in a new browser window.

here is the contents of my views-list-viewname.tpl.php at present

<div class="view-label view-field-field-voucher-image-fid">
  <?php print $field_voucher_image_fid_label ?>
</div>
<div class="view-field view-data-field-voucher-image-fid">
  <a href="/files/sitefolder/<?php print $field_voucher_image[0]['filepath'] ?>" target="_blank"><?php print $field_voucher_image_fid?></a>

<?php print_r($node) ?>
</div>

and the <?php print_r($node) ?> output is

stdClass Object ( [nid] => 28 [node_data_field_voucher_image_field_voucher_image_fid] => 38 [node_data_field_voucher_image_field_voucher_image_title] => [node_data_field_voucher_image_field_voucher_image_alt] => [node_title] => 20% off all drinks [node_changed] => 1214181150 ) 

As you can see I dont even have the filepath property in my array at all.

using Imagefield 5.x-1.2-rc1

Subscribing to this issue with fingers crossed :)