Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Newbie ask for help

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
michelefaccini
Smarty n00b


Joined: 15 Jan 2019
Posts: 3
Location: Italy

PostPosted: Wed Jan 16, 2019 9:04 am    Post subject: Newbie ask for help Reply with quote

Hi all, I had the following with Smarty 2

Code:
$smarty->register_function('smarty_fewchars', 'smarty_fewchars');


I tried the following for Smarty 3 but it doesn't run :

Code:
$smarty->register->templateFunction('smarty_fewchars', 'smarty_fewchars');


Code:
function fewchars($s, $lenght)
{
   $str_to_count = html_entity_decode($s);
   if (mb_strlen($str_to_count, "UTF-8" ) <= $lenght)
   {
      return $s;
   }

   $s2 = mb_substr($str_to_count, 0, $lenght - 3, "UTF-8")."...";

   return $s2;
}

function smarty_fewchars($params, &$smarty)
{
   if (empty($params['s']))
      return '';
   if (empty($params['length']))
      $params['length'] = 255;
   
   return fewchars($params['s'], $params['length']);
}


Please help me.....
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1518

PostPosted: Thu Jan 17, 2019 11:36 am    Post subject: Reply with quote

https://www.smarty.net/docs/en/language.modifier.truncate.tpl
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP