在truncate smarty中显示一个链接

时间:2013-03-03 20:15:30

标签: smarty

在smarty中,我们可以使用它来缩短文本输出:

{$articleTitle}
{$articleTitle|truncate}
{$articleTitle|truncate:30}
{$articleTitle|truncate:30:""}
{$articleTitle|truncate:30:"---"}
{$articleTitle|truncate:30:"":true}
{$articleTitle|truncate:30:"...":true}
{$articleTitle|truncate:30:'..':true: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...
Two Sisters Re..ckout Counter.

我想要显示的是:“... <a href="{$url}">read more</a>” 当你将它应用于代码时,它将是这样的:

{$articleTitle|truncate:30:"... <a href="{$url}">read more</a>":true}

但这不起作用。我怎样才能使它发挥作用?

1 个答案:

答案 0 :(得分:1)

首先尝试在邮件中用单引号替换双引号:

{$articleTitle|truncate:30:"... <a href='{$url}'>read more</a>":true}

如果没有帮助,请尝试为您的消息使用其他变量:

{assign var=readMoreText value="... <a href='{$url}'>read more</a>"}   
{$articleTitle|truncate:30:$readMoreText:true}