Image elseif display issue

6 posts by 3 authors in: Forums > CMS Builder
Last Post: February 24, 2010   (RSS)

By terryally - February 21, 2010 - edited: February 21, 2010

Hello,

I am experiencing some problems in getting the conditional statements in the image display to work.

Your existing code is:
<?php foreach ($showsRecords as $record): ?>
<!-- Display Uploads -->
<?php foreach ($record['tab_image'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="<?php echo $record['tab_blurb'] ?>" />
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="<?php echo $record['tab_blurb'] ?>" />
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a>
<?php endif ?>
<?php endforeach ?>


Which I understand to mean: If there is a thumbnail use it and if there isn't use that image instead. However if there is neither a thumbnail nor image then download the file.

I've substituted the last line to display a generic image but that line is not being executed and that is my query. Why isn't it being executed.

Terry

Re: [terryally] Image elseif display issue

By gkornbluth - February 21, 2010 - edited: February 23, 2010

Hi Terry,

in it's current form your last line is a link to the same image that's referred to in the preceding 'isimage' statement.

If you want to display a generic image you should use something like this:

<?php else: ?>
<img src="http://www.your_site.com/path_to_your_generic_image/generic_image.jpg" width="your_image_width_in_pixels" height="your_image_height_in_pixels" alt="your_alt_text" />
<?php endif ?>


Plus any styling (centering, borders, etc) that you want to include.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [terryally] Image elseif display issue

Hi Terry,

Sorry, uploads are a little funny.

Here's another approach that I found on the forum:

<?php foreach ($your_tableRecords as $record): ?>

<?php if (sizeof($record['your_image_field']) >= 1): ?>

<?php foreach ($record[your_image_field'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" alt="" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" align="center" /></a>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" alt="" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" align="right" />
<?php endif ?>
<?php endforeach ?>

<?php else: ?>
<img src="http://www.your_site.com/path_to_your_generic_image/generic_image.jpg" width="your_image_width_in_pixels" height="your_image_height_in_pixels" alt="your_alt_text" />
<?php endif ?>
<?php endforeach; ?>


But whatever works is the one to use.

Best,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [terryally] Image elseif display issue

By Chris - February 23, 2010

Hi Terry,

Your approach should definitely work. I noticed you're referencing $upload['tab_image_generic'], but you probably want to use $record['tab_image_generic'] instead:

<img src="<?php echo $record['tab_image_generic'] ?>" width="640" height="250" alt="<?php echo $record['tab_blurb'] ?>">

This assumes that your tab_image_generic field is a textfield which contains a URL (either relative or including http://). Is that correct?

Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Image elseif display issue

By terryally - February 24, 2010 - edited: February 28, 2010

Hi Chris,

I tried both what you suggested in the previous message (which I really thought would have worked) and the following and neither worked.

<img src="/lcc_images/lakeside_generic.png" width="640" height="250" >

Unless you can spot something obvious then I am happy to leave this at this point as I have already wrapped the entire thing into a PHP conditional statement which is working.

Regards
Terry