{textformat}
{textformat}
是一个用于格式化文本的 块函数。它一般会清理空格和特殊字符,该函数主要清理空格和特殊字符,对段落按单词边界换行和行缩进等段落格式化处理。
你可以明确指定参数,或者使用预设风格。当前“email”是唯一可用的风格。
参数名称 | 类型 | 必选参数 | 默认值 | 说明 |
---|---|---|---|---|
style | string | No | n/a | 预设风格 |
indent | number | No | 0 | 每行缩进的字符数 |
indent_first | number | No | 0 | 首行缩进的字符数 |
indent_char | string | No | (single space) | 缩进使用的字符 |
wrap | number | No | 80 | 每行长度(换行) |
wrap_char | string | No | \n | 断行使用的字符 |
wrap_cut | boolean | No | FALSE |
设置TRUE 将会按字符换行,而不是按单词边界换行。 |
assign | string | No | n/a | 将输出的内容赋值到模板变量 |
- {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.
原文: https://www.smarty.net/docs/zh_CN/language.function.textformat.tpl