ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
截取 从字符串开始处截取某长度的字符.默认是80个. 你也可以指定第二个参数作为追加在截取字符串后面的文本字串.该追加字串被计算在截取长度中。 默认情况下,smarty会截取到一个词的末尾。 如果你想要精确的截取多少个字符,把第三个参数改为"true" <table border="1" class="CALSTABLE"> <thead> <tr> <th>Parameter Position参数位置</th> <th>Type参数类型</th> <th>Required必需</th> <th>Default默认</th> <th>Description描述</th> </tr> </thead> <tbody> <tr> <td width="20%" align="LEFT" valign="TOP">1</td> <td width="20%" align="LEFT" valign="TOP">integer</td> <td width="20%" align="LEFT" valign="TOP">No</td> <td width="20%" align="LEFT" valign="TOP">80</td> <td width="20%" align="LEFT" valign="TOP"> 截取字符的数量</td> </tr> <tr> <td width="20%" align="LEFT" valign="TOP">2</td> <td width="20%" align="LEFT" valign="TOP">string</td> <td width="20%" align="LEFT" valign="TOP">No</td> <td width="20%" align="LEFT" valign="TOP">...</td> <td width="20%" align="LEFT" valign="TOP"> 截取后追加在截取词后面的字符串 </td> </tr> <tr> <td width="20%" align="LEFT" valign="TOP">3</td> <td width="20%" align="LEFT" valign="TOP">boolean</td> <td width="20%" align="LEFT" valign="TOP">No</td> <td width="20%" align="LEFT" valign="TOP">false</td> <td width="20%" align="LEFT" valign="TOP"> 是截取到词的边界(假)还是精确到字符(真)</td> </tr> </tbody> </table> 例子: articleTitle:`Two Sisters Reunite after Eighteen Years at Checkout Counter.` 模板: ``` _{$articleTitle}_ _{$articleTitle|truncate}_ _{$articleTitle|truncate:30}_ _{$articleTitle|truncate:30:""}_ _{$articleTitle|truncate:30:"---"}_ _{$articleTitle|truncate:30:"":true}_ _{$articleTitle|truncate:30:"...":true}_ ``` 输出: ``` Two Sisters Reunite after Eighteen Years at Checkout Counter. Two Sisters Reunite after Eighteen Years at Checkout Counter. Two Sisters Reunite after... Two Sisters Reunite after Two Sisters Reunite after--- Two Sisters Reunite after Eigh Two Sisters Reunite after E... ```