標籤:style blog java 使用 io 檔案 for 2014
使用smarty,在tpl檔案中如何使用相對路徑調用css&javascript檔案,實際上這個相對路徑的參照物就是以調用該tpl檔案的php檔案來寫。
假如,我在index.php這個檔案中調用template/index.tpl,那麼index.tpl裡面使用的css&javascript檔案的相對路徑就是index.php相對
於這些檔案的路徑。
display用法:
// from PHP script , for linux
$smarty->display("file:/export/templates/index.tpl");
$smarty->display("file:/path/to/my/templates/menu.tpl");
// from PHP script, for windows
$smarty->display("file:C:/export/templates/index.tpl");
$smarty->display("file:F:/path/to/my/templates/menu.tpl");
include用法:
{include file="模板存放的路徑"}
//from within Smarty Template , for windows & for linux
{include file="file:file:D:/usr/local/share/templates/navigation.tpl"}
{include file="file="file:/usr/local/share/templates/navigation.tpl"}
foreach用法:
{foreach [name="the name of the foreach loop for accessing foreach properties"] from="the name of the array you are looping through" item="the name of the variable that is current element" }
......
{/foreach}
還可以使用$smarty.foreach.foreachname.varname形式來訪foreach的屬性,foreachname指的是foreach中指定的name屬性值;
varname:
iteration(iteration is used to display the current loop iteration, iteration always starts with 1 and incremented by one each iteration);
first(first is set to true if the current foreach iteration is the first one);
last(last is set to true if the current foreach iteration is the last one);
show(show is used as a parameter to foreach. show is a boolean value, true or false. If false, the foreach will not be displayed. If there is a foreachelse present, that will be alternately displayed.);
total(total is used to display the number of iterations that this foreach will loop. This can be used inside or after the foreach.)