Hello,
I'm working on an image slideshow. It's based on a field collaction that might have an image, an image title and a link. Everything works fine so far. But everytime I activate the Drupal caches I receive the following error message:
Notice: Undefined index: target in include() (on line 38 in /.../node--slideshow.tpl.php).
Here is line 38:
echo '<div class="slideshow-element">'. l(theme('image', array('path' => image_style_url('slideshow', $element->field_bilder['und'][0]['uri']), 'alt' => $element->field_bilder['und'][0]['title'], 'title' => $element->field_bilder['und'][0]['title'])). $image_title, $element->field_link['und'][0]['url'], array('html' => true, 'attributes' => array('target' => $element->field_link['und'][0]['attributes']['target']))) .'</div>';
And here the complete code:
if (!empty($content['field_slideshow_element']['#items'][0]['value'])) {
echo '<div class="slideshow-wrapper"><div class="slideshow">';
foreach ($content['field_slideshow_element']['#items'] as $slideshowelement) {
$collection = entity_load('field_collection_item', $slideshowelement);
foreach ($collection as $element) {
$image_title = '';
if (!empty($element->field_bilder['und'][0]['title'])) {
$image_title = '<span class="slideshow-text">'. $element->field_bilder['und'][0]['title'] .'</span>';
}
if (!empty($element->field_bilder['und'][0]['fid']) && !empty($element->field_link['und'][0]['url'])) {
// HERE COMES LINE 38
echo '<div class="slideshow-element">'. l(theme('image', array('path' => image_style_url('slideshow', $element->field_bilder['und'][0]['uri']), 'alt' => $element->field_bilder['und'][0]['title'], 'title' => $element->field_bilder['und'][0]['title'])). $image_title, $element->field_link['und'][0]['url'], array('html' => true, 'attributes' => array('target' => $element->field_link['und'][0]['attributes']['target']))) .'</div>';
}
elseif (!empty($element->field_bilder['und'][0]['fid']) && empty($element->field_link['und'][0]['url'])) {
echo '<div class="slideshow-element">'. theme('image', array('path' => image_style_url('slideshow', $element->field_bilder['und'][0]['uri']), 'alt' => $element->field_bilder['und'][0]['title'], 'title' => $element->field_bilder['und'][0]['title'])). $image_title .'</div>';
}
}
}
echo '</div><div class="slideshow-prev"></div><div class="slideshow-next"></div></div>';
}
Do I have a mistake in my code or is it a bug? It's suspect because I only receive this error when I turn the caches on. Maybe I'm overseeing something very trivial.
Thank you!
Stefan
Comments
Comment #1
jmuzz commentedI don't know what caches would have to do with it either, but if you check _link_sanitize you'll see the 'target' attribute will be unset when it is the default, so it's valid for a link to not have it.