Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

If image exists...

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 08-23-2003, 10:42 PM
 
John7 John7 is offline
 

Senior Member
  
Join Date: Jan 2003
Posts: 136
 

Default If image exists...

How do we do an if then statement in smarty such as...

Code:
if image exists then display image else do nothing

I know this has to be pretty simple.

Can anyone help? Funky?

Thanks, John7
Reply With Quote
  #2  
Old 08-25-2003, 09:49 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

Okay - there is not a standard smarty or xcart way of doing this but....

first:

create a new modifier file: modifier.file_exist.php and save it into your smarty plugins folder.

Code:
<?php /* * Smarty plugin * ------------------------------------------------------------- * Type: modifier * Name: file_exists * Purpose: checks if a file exist * ------------------------------------------------------------- */ function smarty_modifier_file_exists($params, &$smarty) { extract($params); if (empty($file)) { $smarty->trigger_error("assign: missing 'file' parameter"); return; } return file_exists($file); } ?>

Then in the template where you wish for the file check to be used:

{assign var="file" value="the_image_check_for.gif"}
{if $file|file_exists}
[img]{$file}[/img]
{else}
Show another image
{/if}

That'll do it
__________________
ex x-cart guru
Reply With Quote
  #3  
Old 08-25-2003, 09:54 AM
 
John7 John7 is offline
 

Senior Member
  
Join Date: Jan 2003
Posts: 136
 

Default Awsome!!!

Awsome!!!

I'm going to go test it out now.

I'll keep you posted on how this turns out!

Thanks Funky!!!

JoHn7
Reply With Quote
  #4  
Old 08-25-2003, 06:59 PM
 
John7 John7 is offline
 

Senior Member
  
Join Date: Jan 2003
Posts: 136
 

Default It works!!!

It works!!! Perfectly!!!

Thanks so much!!!

John7
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:56 PM.

   

 
X-Cart forums © 2001-2020