MyBB Hacks

Full Version: show image only if exists
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi all, i'm a newby in mybb and php, what i'm triyng to do is to show an image only if the related file exists on the server, i modified the forumbit_depth2_forum template but the image is always added even if the file is not in the server, can you help me to understand what's wrong in the code? Thanks.

<tr>
<td class="{$bgcolor}" align="center" valign="top" width="1"><img src="{$theme['imgdir']}/{$lightbulb['folder']}.gif" alt="{$lightbulb['altonoff']}" title="{$lightbulb['altonoff']}" class="ajax_mark_read" id="mark_read_{$forum['fid']}" /></td>
<td class="{$bgcolor}" align="center" valign="top" width="1">

<?php if(file_exists("{$theme['imgdir']}/icon_{$forum['fid']}.png")) ?>
<img height="100" width="100"  src="{$theme['imgdir']}/icon_{$forum['fid']}.png"  title="" class="ajax_mark_read" />

</td>
<td class="{$bgcolor}" valign="top">
<strong><a href="{$forum_url}">{$forum['name']}</a></strong>{$forum_viewers_text}<div class="smalltext">{$forum['description']}{$modlist}{$subforums}</div>
</td>
<td class="{$bgcolor}" valign="top" align="center" style="white-space: nowrap">{$threads}{$unapproved['unapproved_threads']}</td>
<td class="{$bgcolor}" valign="top" align="center" style="white-space: nowrap">{$posts}{$unapproved['unapproved_posts']}</td>
<td class="{$bgcolor}" valign="top" align="right" style="white-space: nowrap">{$lastpost}</td>
</tr>
You can't enter PHP into templates unless you have a modification which allows you to do so.

Also, check the syntax of 'if' in PHP: http://php.net/manual/en/control-structures.if.php
I solved, thanks.
Reference URL's