smarty-2014-02-28

來源:互聯網
上載者:User

標籤: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.)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.