vendredi 8 mai 2015

k2 item.php extra fields Display default image if left blank

I am currently buiding a site in joomla and using k2 to manage the content I am creating a template in k2, for item.php. I wish to use an extra field to display a header image on the item.

I have managed to Implement this using the following

Toward top of document

<?php  
$extrafields = array();
foreach($this->item->extra_fields as $item)
{    
$extrafields[$item->id] = $item->value;
}   
?>

Positioned where required

      <?php if($extrafields[2]!=''):?> <!-- if filled in, then call data -->
<?php echo $extrafields[2];?> <!-- actual data call -->
<?php endif; ?>

I have succeeded in that If i fill in the extra field i get my header image exactly where i want it, My problem is if i leave the field blank it is meant to revert to a default image, but insted i get the following error

Notice: Undefined offset: 2 in (URL)\item.php on line 194

I am not sure where I have gone wrong. I'm sure I need an or statement but its Friday and my brain is fried. any help much appreciated!

Iameki

Aucun commentaire:

Enregistrer un commentaire