简体   繁体   中英

If file_exists Smarty

I'm new coding and Could someone tell me what i am doing wrong.

I want to see if a image exists in a folder but it won't display the image if it exists.

{assign var="backimg" value="/thumbs/backgrounds/movie_bg/`$mov.title|lower|replace:' ':'_'`.jpg"}
{ if file_exists($backimg) }
<div class="container_inner"
style="background:url(/thumbs/backgrounds/movie_bg/{$mov.title|lower|replace:' ':'_'}.jpg)no-repeat center;">
{else}
<div class="container_inner">
{/if}

Could someone tell me if there is anything wrong with my code.

Smarty is a templating language. You don't write PHP code into a template like that. You do the logic in the PHP code that calls the template, assigning whatever values are needed to render the page correctly to the template, and then render the template.

// In the PHP code.
// (Simplified. The actual code to initialize Smarty will usually be more complex.)
$smarty = new Smarty();
$smarty->assign("file_exists", file_exists('/file/path'));
$smarty->display('mytemplate.tpl');

// In the 'mytemplate.tpl' template file.
{if $file_exists}
    <p>File exist!</p>
{else}
    <p>File doesn't exist</p>
{/if}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM