I am trying to create a custom slideshow using Views. Please not that I am not using the Views Slideshow Module
What I need to accomplish is to wrap the the relative URL for the images within a container. So, my field template should generate
/sites/default/files/background.jpg
The problem that I am having is gaining access to the URI so that I can write the raw value into some div tags. So, since that is the area that I am having difficulty with, I am focusing on only writing the URL not all the div containers; that will come later.
As for the image, I have a simple content type that has only two fields: title and the image itself. I have created the view that lists the images I am looking for. Now to customize the field template within the view. Here is my code:
<?php
$node = node_load($row->nid);
$field_name = "field_image";
$delta = 0;
$field = field_get_items('node', $node, $field_name);
$output = field_view_value('node', $node, $field_name, $field[$delta]);
print ($output['#item']['uri']);
/* Everything below is for Debugging Purposes */
print "<br><br>";
print "Field: ";
print_r($field);
print "<br><br>";
print "Output: ";
print_r($output);
print "<br><br>";
?>
If you look at the output below, I get a URI that says:
public://public://sandy_beach_banner.jpg
This is correct. I will be running it through file_create_Url() later as soon as I figure out how to make it a relative link and not absolute.
However, I get the error message:
Notice: Undefined index: #item in include() (line 11 of
/var/www2/html/annex/sites/all/themes/mytheme/templates/views-
view-field--banner-slide-show--field-image.tpl.php)
Line 11 in my file references
print ($output['#item']['uri']);
This I don't understand. If I wasn't referencing it correctly, I wouldn't get the URI value I am looking for. So...this confuses me greatly. I am trying to following the example that I found here: Rendering Drupal 7 Fields The Right Way because from what I can tell, this will also work in D8 (I could be wrong). That, and I want to legimately learn how to do this the right way.
Any advice here would be greatly appreciated.
Output
public://public://sandy_beach_banner.jpg
Field: Array ( [0] => Array ( [fid] => 5 [uid] => 1 [filename] => sandy_beach_banner.jpg [uri] => public://sandy_beach_banner.jpg [filemime] => image/jpeg [filesize] => 30663 [status] => 1 [timestamp] => 1444690263 [alt] => Sandy Beach [title] => Sandy Beach [width] => 800 [height] => 200 ) )
Output: Array ( [#theme] => image_formatter [#item] => Array ( [fid] => 5 [uid] => 1 [filename] => sandy_beach_banner.jpg [uri] => public://sandy_beach_banner.jpg [filemime] => image/jpeg [filesize] => 30663 [status] => 1 [timestamp] => 1444690263 [alt] => Sandy Beach [title] => Sandy Beach [width] => 800 [height] => 200 ) [#image_style] => [#path] => [#access] => 1 )
public://public://nyc_banner.jpg
Field: Array ( [0] => Array ( [fid] => 4 [uid] => 1 [filename] => nyc_banner.jpg [uri] => public://nyc_banner.jpg [filemime] => image/jpeg [filesize] => 480360 [status] => 1 [timestamp] => 1444690227 [alt] => NYC Banner [title] => NYC Banner [width] => 1200 [height] => 492 ) )
Output: Array ( [#theme] => image_formatter [#item] => Array ( [fid] => 4 [uid] => 1 [filename] => nyc_banner.jpg [uri] => public://nyc_banner.jpg [filemime] => image/jpeg [filesize] => 480360 [status] => 1 [timestamp] => 1444690227 [alt] => NYC Banner [title] => NYC Banner [width] => 1200 [height] => 492 ) [#image_style] => [#path] => [#access] => 1 )
public://public://hindu_banner.jpg
Field: Array ( [0] => Array ( [fid] => 3 [uid] => 1 [filename] => hindu_banner.jpg [uri] => public://hindu_banner.jpg [filemime] => image/jpeg [filesize] => 508630 [status] => 1 [timestamp] => 1444690189 [alt] => Hindu Banner [title] => Hindu Banner [width] => 2000 [height] => 560 ) )
Output: Array ( [#theme] => image_formatter [#item] => Array ( [fid] => 3 [uid] => 1 [filename] => hindu_banner.jpg [uri] => public://hindu_banner.jpg [filemime] => image/jpeg [filesize] => 508630 [status] => 1 [timestamp] => 1444690189 [alt] => Hindu Banner [title] => Hindu Banner [width] => 2000 [height] => 560 ) [#image_style] => [#path] => [#access] => 1 )