Smarty:textformat函數(shù)

2018-10-17 11:58 更新

{textformat}

{textformat}是一個用于格式化文本的 塊函數(shù)。 它一般會清理空格和特殊字符,該函數(shù)主要清理空格和特殊字符,對段落按單詞邊界換行和行縮進(jìn)等段落格式化處理。

你可以明確指定參數(shù),或者使用預(yù)設(shè)風(fēng)格。當(dāng)前email是唯一可用的風(fēng)格。

參數(shù)名稱類型必選參數(shù)默認(rèn)值說明
stylestringNon/a預(yù)設(shè)風(fēng)格
indentnumberNo0每行縮進(jìn)的字符數(shù)
indent_firstnumberNo0首行縮進(jìn)的字符數(shù)
indent_charstringNo(single space)縮進(jìn)使用的字符
wrapnumberNo80每行長度(換行)
wrap_charstringNo\n斷行使用的字符
wrap_cutbooleanNoFALSE設(shè)置TRUE將會按字符換行,而不是按單詞邊界換行。
assignstringNon/a將輸出的內(nèi)容賦值到模板變量

Example 8.22. {textformat}

   {textformat wrap=40}

   This is foo.
   This is foo.
   This is foo.
   This is foo.
   This is foo.
   This is foo.

   This is bar.

   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.

   {/textformat}

輸出:

   This is foo. This is foo. This is foo.
   This is foo. This is foo. This is foo.

   This is bar.

   bar foo bar foo foo. bar foo bar foo
   foo. bar foo bar foo foo. bar foo bar
   foo foo. bar foo bar foo foo. bar foo
   bar foo foo. bar foo bar foo foo.
   {textformat wrap=40 indent=4}

   This is foo.
   This is foo.
   This is foo.
   This is foo.
   This is foo.
   This is foo.

   This is bar.

   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.

   {/textformat}

輸出:

   This is foo. This is foo. This is
   foo. This is foo. This is foo. This
   is foo.

   This is bar.

   bar foo bar foo foo. bar foo bar foo
   foo. bar foo bar foo foo. bar foo
   bar foo foo. bar foo bar foo foo.
   bar foo bar foo foo. bar foo bar
   foo foo.
   {textformat wrap=40 indent=4 indent_first=4}

   This is foo.
   This is foo.
   This is foo.
   This is foo.
   This is foo.
   This is foo.

   This is bar.

   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.

   {/textformat}

輸出:

   This is foo. This is foo. This
   is foo. This is foo. This is foo.
   This is foo.

   This is bar.

   bar foo bar foo foo. bar foo bar
   foo foo. bar foo bar foo foo. bar
   foo bar foo foo. bar foo bar foo
   foo. bar foo bar foo foo. bar foo
   bar foo foo.
   {textformat style="email"}

   This is foo.
   This is foo.
   This is foo.
   This is foo.
   This is foo.
   This is foo.

   This is bar.

   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.
   bar foo bar foo     foo.

   {/textformat}

輸出:

   This is foo. This is foo. This is foo. This is foo. This is foo. This is
   foo.

   This is bar.

   bar foo bar foo foo. bar foo bar foo foo. bar foo bar foo foo. bar foo
   bar foo foo. bar foo bar foo foo. bar foo bar foo foo. bar foo bar foo
   foo.

參見 {strip} 和 自動換行.

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號