2013-03-03 92 views
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} 

但這不起作用。我怎樣才能使它工作?

回答

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}