I'm currently working through self-set tasks to learn Views and pre-processing in Drupal 7. I've created an unformatted view which creates a list of images (which are linked to a content-type but it seems if I replace the fields in view with node:type then I get a link to the node page which is not what I'm after) to place them in a block. I've placed the block into the highlight region and have written a views-view-fields--image.tpl.php file to output the list into various unordered list formats which are then transformed by jCarousel or the featureList jQuery plug-ins.
On top of this, I've created a page--front.tpl.php file to restyle the front page and it appears to work in that the CSS, js and HTML are working correctly and the carousel and lists appear & work in the defined block.
However when I leave the front page to another page where the view should not appear, I get the following error:
Notice: Undefined property: stdClass::$_field_data in iaintest_preprocess_views_view_fields() (line 10 of /Applications/XAMPP/xamppfiles/htdocs/drupal/sites/all/themes/iaintest/template.php).
To pre-process the list that the view outputs, I've written the following pre-process code:
function iaintest_preprocess_views_view_fields (&$variables) {
if (!$variables['view']->result[0]->_field_data) {
// Line 10 where the error occurs.
}
else {
drupal_add_css(path_to_theme() . '/jcarousel/skins/tango/skin.css');
drupal_add_css(path_to_theme() . '/featureList.css');
$js = "
jQuery.noConflict();
jQuery(document).ready(function(){
jQuery('#mycarousel').jcarousel();
jQuery.featureList(
jQuery('#tabs li a'),
jQuery('#output li'), {
start_item: 1
}
);
});";
drupal_add_js($js, 'inline');
$items = array();
foreach ($variables['view']->result as $key => $vars) {
foreach ($variables['view']->result[0]->_field_data['nid']['entity']->field_images['und'] as $k => $v) {
$variables['carousel'][] = array(
'uri' => $v['uri'],
'alt' => $v['alt'],
'title' => $v['title']
);
}
}
}
}
I have tried using drupal_is_front_page()
or $variable['is_front'] === TRUE
to limit this part of the preprocessing to the front page, which is the only place where the original view appears.
Is this possible at all, or have I misunderstood anything?
foreach()
-statements you are using seem weird.