PDA

View Full Version : How Do I Prevent Broken Images


Joe Boxer
01-11-2007, 11:20 PM
If a thumbnail is uploaded, it shows up on the link detail page perfectly.

But if no image is uploaded, a broken image is displayed.

How can I adjust the code so that the text ("Image:") and corresponding image are only displayed if an image was uploaded?

Current code is shown below:


<!-- START LINK FIELDS DISPLAY -->
{foreach from=$fields item=field}
{assign var="key" value=$field.name}
<tr>
{assign var="field_name" value='field_'|cat:$field.name}
<td valign="top"><strong>{$lang.$field_name}:</strong></td>
<td>
{if $link.$key || ($link.$key eq '0')}
{if ($field.type eq 'text') || ($field.type eq 'textarea')}
{if $config.html_tags}
{$link.$key}
{else}
{text_html aText=$link.$key}
{/if}
{elseif $field.type eq 'checkbox'}
{array_to_lang values=$link.$key name=$field.name}
{elseif $field.type eq 'storage'}
<a href="{$config.base}{$config.dir}uploads/{$link.$key}">{$lang.download}</a>
{elseif $field.type eq 'image'}
<img src="{$config.base}{$config.dir}uploads/{$link.$key}" width="{$field.image_width}" height="{$field.image_height}" />
{elseif $field.type eq 'combo'}
{assign var="field_combo" value="field_"|cat:$field.name|cat:'_'|cat:$link.$key}
{$lang.$field_combo}
{elseif $field.type eq 'radio'}
{assign var="field_radio" value="field_"|cat:$field.name|cat:'_'|cat:$link.$key}
{$lang.$field_radio}
{/if}
{else}
{$lang.not_available}
{/if}
</td>
</tr>
{/foreach}
<!-- END LINK FIELDS DISPLAY -->

Thanks, Joe

Michael Hill
01-12-2007, 06:27 AM
Hello, Joe,

The fragment of code for thumbnails in your templates/YourCurrentTemplate/view-link.tpl is (for GreenLeaves, for example):


<td valign="top" style="padding: 0 0 0 10px;" >
{if $config.thumbshot}
<div class="preview"><img src="http://open.thumbshots.org/image.pxf?url={$link.url}" /></div>
{/if}
</td>


For change background with no-preview image, open css file of your template and find this code:


div.preview
{
background-image: url('../img/no-preview.gif');
background-repeat: no-repeat;
background-position: top left;
border: 1px solid #ccc;
height: 90px;
width: 120px;
}


Then you can delete background-image or replace it with your own.

Thank you, hope, that help!

Joe Boxer
01-12-2007, 03:02 PM
Michael:

Sorry, I should have been a bit more detailed in my question. I am not using ThumbShots.

Rather, I am letting visitors submit link along with uploading their logo or image of their choosing.

So, when their detailed listing is displayed, the script needs to determine if a logo/image was uploaded. If so, it should display it. If no image was uploaded, then no image should be displayed - certainly not a broken one.

I'm hoping that the same logic for displaying the image on the link detail page, can be used on the main pages.

Thanks, Joe

Michael Hill
01-17-2007, 09:07 AM
Hi, Joe,

In accordance with above, you can check presence of image. And in depending on this use background image or load image from directory.

I am glad to help.