Smarty中的註解與截斷功能詳解

php中世界最好的语言
發布: 2023-03-20 19:54:01
原創
1505 人瀏覽過

Smarty是一個使用PHP寫出來的模板引擎。它分離了邏輯程式碼和外在的內容,提供了一種易於管理和使用的方法。這篇文章主要介紹了Smarty中的註釋和截斷功能介紹,這兩個功能都是Smarty中不太常用的功能,但非常實用,需要的朋友可以參考下。

註解

複製程式碼 程式碼如下:

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

{* 這是一個多行
   Smarty註解
   並沒有傳送到瀏覽器
*}

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

http://www.itlearner.com/code/smarty_cn/language.basic.syntax.html

截斷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 Re..ckout Counter.

可以不用在PHP裡截取了:http://www.itlearner.com/code/smarty_cn/language.modifier.truncate.html

#相關推薦:

smarty如何嵌套循環

Smarty模板如何使用變數調節器

##Smarty如何生成簡單的表單元素


以上是Smarty中的註解與截斷功能詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!