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

這篇文章主要介紹了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.