0

私は新しいコーディングで、誰かが私が間違っていることを教えてくれますか?

フォルダに画像が存在するかどうかを確認したいのですが、存在する場合は画像が表示されません。

{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}

私のコードに何か問題があるかどうか誰かに教えてもらえますか。

4

1 に答える 1

0

Smarty はテンプレート言語です。そのようなテンプレートに PHP コードを記述することはありません。テンプレートを呼び出す PHP コードでロジックを実行し、ページを正しくレンダリングするために必要な値をテンプレートに割り当ててから、テンプレートをレンダリングします。

// 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}
于 2013-09-14T09:41:07.807 に答える