X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   If image exists... (https://forum.x-cart.com/showthread.php?t=4105)

John7 08-23-2003 10:42 PM

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

funkydunk 08-25-2003 09:49 AM

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 :)

John7 08-25-2003 09:54 AM

Awsome!!!
 
Awsome!!!

I'm going to go test it out now.

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

Thanks Funky!!!

JoHn7

John7 08-25-2003 06:59 PM

It works!!!
 
It works!!! Perfectly!!!

Thanks so much!!!

John7


All times are GMT -8. The time now is 09:46 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.