{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 将输出的内容赋值到模板变量


Example 8.22. {textformat}

  1. {textformat wrap=40}
  2.  
  3. This is foo.
  4. This is foo.
  5. This is foo.
  6. This is foo.
  7. This is foo.
  8. This is foo.
  9.  
  10. This is bar.
  11.  
  12. bar foo bar foo foo.
  13. bar foo bar foo foo.
  14. bar foo bar foo foo.
  15. bar foo bar foo foo.
  16. bar foo bar foo foo.
  17. bar foo bar foo foo.
  18. bar foo bar foo foo.
  19.  
  20. {/textformat}
  21.  
  22.  

输出:

  1.  
  2. This is foo. This is foo. This is foo.
  3. This is foo. This is foo. This is foo.
  4.  
  5. This is bar.
  6.  
  7. bar foo bar foo foo. bar foo bar foo
  8. foo. bar foo bar foo foo. bar foo bar
  9. foo foo. bar foo bar foo foo. bar foo
  10. bar foo foo. bar foo bar foo foo.
  11.  
  1. {textformat wrap=40 indent=4}
  2.  
  3. This is foo.
  4. This is foo.
  5. This is foo.
  6. This is foo.
  7. This is foo.
  8. This is foo.
  9.  
  10. This is bar.
  11.  
  12. bar foo bar foo foo.
  13. bar foo bar foo foo.
  14. bar foo bar foo foo.
  15. bar foo bar foo foo.
  16. bar foo bar foo foo.
  17. bar foo bar foo foo.
  18. bar foo bar foo foo.
  19.  
  20. {/textformat}
  21.  
  22.  

输出:

  1.  
  2. This is foo. This is foo. This is
  3. foo. This is foo. This is foo. This
  4. is foo.
  5.  
  6. This is bar.
  7.  
  8. bar foo bar foo foo. bar foo bar foo
  9. foo. bar foo bar foo foo. bar foo
  10. bar foo foo. bar foo bar foo foo.
  11. bar foo bar foo foo. bar foo bar
  12. foo foo.
  13.  
  1. {textformat wrap=40 indent=4 indent_first=4}
  2.  
  3. This is foo.
  4. This is foo.
  5. This is foo.
  6. This is foo.
  7. This is foo.
  8. This is foo.
  9.  
  10. This is bar.
  11.  
  12. bar foo bar foo foo.
  13. bar foo bar foo foo.
  14. bar foo bar foo foo.
  15. bar foo bar foo foo.
  16. bar foo bar foo foo.
  17. bar foo bar foo foo.
  18. bar foo bar foo foo.
  19.  
  20. {/textformat}
  21.  

输出:

  1.  
  2. This is foo. This is foo. This
  3. is foo. This is foo. This is foo.
  4. This is foo.
  5.  
  6. This is bar.
  7.  
  8. bar foo bar foo foo. bar foo bar
  9. foo foo. bar foo bar foo foo. bar
  10. foo bar foo foo. bar foo bar foo
  11. foo. bar foo bar foo foo. bar foo
  12. bar foo foo.
  13.  
  1. {textformat style="email"}
  2.  
  3. This is foo.
  4. This is foo.
  5. This is foo.
  6. This is foo.
  7. This is foo.
  8. This is foo.
  9.  
  10. This is bar.
  11.  
  12. bar foo bar foo foo.
  13. bar foo bar foo foo.
  14. bar foo bar foo foo.
  15. bar foo bar foo foo.
  16. bar foo bar foo foo.
  17. bar foo bar foo foo.
  18. bar foo bar foo foo.
  19.  
  20. {/textformat}
  21.  
  22.  

输出:

  1.  
  2. This is foo. This is foo. This is foo. This is foo. This is foo. This is
  3. foo.
  4.  
  5. This is bar.
  6.  
  7. bar foo bar foo foo. bar foo bar foo foo. bar foo bar foo foo. bar foo
  8. bar foo foo. bar foo bar foo foo. bar foo bar foo foo. bar foo bar foo
  9. foo.
  10.  
  11.  

参见 {strip}自动换行.

原文: https://www.smarty.net/docs/zh_CN/language.function.textformat.tpl