标签:
assign(array(‘data‘=>$blog));
用assign方法把数组$blog换名为data($blog为二维数组),
{foreach from=$data item=‘m‘}
<h3>{$m.blog_title}</h3>
<ul>
<p>{$m.blog|truncate:100}</p>
</ul>{/foreach}按照上述代码可以调用smarty传过来的数据
2.smarty截取字符串函数truecate
从字符串开始处截取某长度的字符,默认的长度为80
指定第二个参数作为截取字符串的长度
默认情况下,smarty会截取到一个词的末尾,
如果需要精确到截取多少个字符可以使用第三个参数,将其设为”true”
具体用法如下:
{$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…
标签:
原文地址:http://www.cnblogs.com/xiaoshuai666/p/5780120.html