Smarty 是什么?
为什么使用?
用例和工作流程
语法比较
模板继承
最佳实践
速成课程
{textformat}
是用于格式化文本的块函数。它可以清除空格和特殊字符,并且通过换行和缩进的方式来格式化段落。
您可以明确设置参数,或使用预置样式。目前,““email””是唯一可用的样式。
属性名称 | 类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
样式 | 字符串 | 否 | n/a | 预置样式 |
缩进 | 数字 | 否 | 0 | 每行缩进的字符数 |
首行缩进 | 数字 | 否 | 0 | 首行缩进的字符数 |
缩进字符 | 字符串 | 否 | (单个空格) | 缩进的字符(或字符串) |
换行 | 数字 | 否 | 80 | 每行换多少个字符 |
换行字符 | 字符串 | 否 | \n | 用此字符(或字符串)换行 |
截断换行 | 布尔值 | 否 | FALSE |
如果为 TRUE ,则换行将在确切的字符处截断,而不是按单词边界截断 |
分配 | 字符串 | 否 | n/a | 输出分配给的模板变量 |
示例 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.