當前位置:才華齋>計算機>php語言>

PHP框架之Smarty中的註釋和截斷功能介紹

php語言 閱讀(1.75W)

這篇文章主要介紹了Smarty中的`註釋和截斷功能介紹,這兩個功能都是Smarty中不太常用的功能,但非常實用,需要的朋友可以參考下。更多訊息請關注應屆畢業生網。

PHP框架之Smarty中的註釋和截斷功能介紹

  註釋

程式碼如下:

{* 這是一個單行Smarty註釋 來自於,網頁原始碼裡看不見*}

{* 這是一個多行

Smarty註釋

並不傳送到瀏覽器

*}

模板註釋由星號包圍,繼而由分隔符包圍,型如:{* 這是一個註釋 *}。Smarty註釋不會在最終模板的輸出中顯示,這點和不同。前者對於在模板中插入內部註釋有用,因為沒有人能看到。;-)

  截斷truncate

程式碼如下:

$smarty->assign('hxtitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');

模板為:

程式碼如下:

{$hxtitle}

{$hxtitle|truncate}

{$hxtitle|truncate:30}

{$hxtitle|truncate:30:""}

{$hxtitle|truncate:30:"---"}

{$hxtitle|truncate:30:"":true}

{$hxtitle|truncate:30:"...":true}

{$hxtitle|truncate:30:'..':true:true}

輸出為:

程式碼如下:

Two Sisters Reunite after Eighteen Years at Checkout Counter.

Two Sisters Reunite after Eighteen Years at Checkout Counter.

Two Sisters Reunite after...

Two Sisters Reunite after

Two Sisters Reunite after---

Two Sisters Reunite after Eigh

Two Sisters Reunite after E...

Two Sisters t Counter.