在ecshop模板中設置了{$goods.goods_name|truncate:10:''}標題后面還是一樣會跟著省略號 ... 該如何解決:
A5源碼提供該ecshop教程:
1.首先ecshop的模板引擎不完全是smarty 所以在truncate函數上是有區別的
找到 cls_template.php 搜索truncate 你會發現以下代碼
case 'truncate':
$p = 'sub_str(' . $p . ",$s[1])";
break;
這里的 sub_str是ec的一個自定義函數在 lib_base.php文件中的
代碼如下:
function sub_str($str, $length = 0, $append = true)
{
$str = trim($str);
$strlength = strlen($str);
if ($length == 0 || $length >= $strlength)
{
return $str;
}
elseif ($length < 0)
{
$length = $strlength + $length;
if ($length < 0)
{
$length = $strlength;
}
}
if (function_exists('mb_substr'))
{
$newstr = mb_substr($str, 0, $length, EC_CHARSET);
}
elseif (function_exists('iconv_substr'))
{
$newstr = iconv_substr($str, 0, $length, EC_CHARSET);
}
else
{
//$newstr = trim_right(substr($str, 0, $length));
$newstr = substr($str, 0, $length);
}
if ($append && $str != $newstr)
{
$newstr .= '...';
}
return $newstr;
}
其中 仔細看
這個函數有3個參數 但是在模板引擎文件中只代了2個參數
2. 以下提供兩種方法修改:
方法一
找到 cls_template.php 搜索truncate
case 'truncate':
$p = 'sub_str(' . $p . ",$s[1],$s[2])";
break;
然后在你的后臺清除一下緩存
{$goods.goods_name|truncate:10:false}
就只顯示5個字 也不會出現...
方法二
直接用代碼刪除頁面顯示中的省略號,找到lib_base.php中
if ($append && $str != $newstr)
{
$newstr .= '...';
}
這樣{$goods.goods_style_name}也不會顯示 ...
這里A5源碼推薦大家使用第一種方法
新聞熱點
疑難解答