Smarty變數

變數

內容列表

$template_dir [範本目錄變數]

[從PHP分配的變數]

[從配置檔讀取的變數]

[{$smarty} 保留變數]

Smarty有幾種不同類型的變數.

變數 的類型取決於它的首碼是什麼符號(或者被什麼符號包圍)

Smarty的變數可以直接被輸出或者作為函數屬性和修飾符(modifiers)的參數,或者用於內部的條件運算式等等.

如果要輸出一個變數,只要用定界符將它括起來就可以.例如:

 

{$Name}

{$Contacts[row].Phone}

<body bgcolor="{#bgcolor#}">

 

 

從PHP分配的變數

內容列表

關聯數組

數組下標

對象

 

調用從PHP分配的變數需在前加"$"符號.(譯注:同php一樣)
調用範本內的assign函數分配的變數也是這樣.(譯注:也是用$加變數名來調用)


例 4-1.分配的變數

index.php:


$smarty = new Smarty;
$smarty->assign('firstname', 'Doug');
$smarty->assign('lastLoginDate', 'January 11th, 2001');
$smarty->display('index.tpl');

index.tpl:

Hello {$firstname}, glad to see you could make it.
<p>
Your last login was on {$lastLoginDate}.

OUTPUT:

Hello Doug, glad to see you could make it.
<p>
Your last login was on January 11th, 2001.


上一篇: Smarty數學運算 下一篇: Smarty從配置檔讀取的變數