Smarty:textformat函数

2018-10-17 11:58 更新

{textformat}

{textformat}是一个用于格式化文本的 块函数。 它一般会清理空格和特殊字符,该函数主要清理空格和特殊字符,对段落按单词边界换行和行缩进等段落格式化处理。

你可以明确指定参数,或者使用预设风格。当前email是唯一可用的风格。

参数名称类型必选参数默认值说明
stylestringNon/a预设风格
indentnumberNo0每行缩进的字符数
indent_firstnumberNo0首行缩进的字符数
indent_charstringNo(single space)缩进使用的字符
wrapnumberNo80每行长度(换行)
wrap_charstringNo\n断行使用的字符
wrap_cutbooleanNoFALSE设置TRUE将会按字符换行,而不是按单词边界换行。
assignstringNon/a将输出的内容赋值到模板变量

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} 和 自动换行.

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号