我有Smarty模板文件。當從Smarty傳遞到php時,$ listing.activation_date爲null。任何解決方案將smarty var傳遞給php
{$listing.activation_date}
{php}
$startDate = strtotime('now');
$interval = $startDate - strtotime($this->get_template_vars('$listing.activation_date'));
{$listing.activation_date} = 2012-Sep-05
我已經改變了$ Smarty的,以$是爲了防止非對象錯誤。
$this->assign("interval", $interval);
$days = floor($this/ (60 * 60 * 24)); {/php}
{if $days < 1} <img src=" {$GLOBALS.site_url}/templates/Natural/main/images/new.gif"/>
{/if}
在{php}中是$天,然後在Smarty中是$天< 1?
Smarty用於表示。在「常規」php腳本中進行所有計算,並將計算出的值傳遞給Smarty。這是(在我看來)使用模板引擎的正確方法。 –