0

在 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}

但这不起作用。我怎样才能让它工作?

4

1 回答 1

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}
于 2013-03-03T21:59:48.250 回答