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

Static function, unknown modifier

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Jerc
Smarty Rookie


Joined: 26 Jan 2010
Posts: 30
Location: Slovenia / Ljubljana

PostPosted: Fri May 23, 2014 1:03 pm    Post subject: Static function, unknown modifier Reply with quote

I have a tiny problem with my template and I'm not sure if this is a Smarty bug or I just made a mistake in the code.

PHP
Code:

// class
namespace WK;
class Utf {
  public static toUtf($str) { return $str; }
}
// code
$smarty->registerClass('Utf', 'WK\Utf');
$smarty->assign('now', time());


.tpl
Code:

{$now|date_format:"%A, %B %e, %Y"|Utf::toUtf8}


Exception:
unknown modifier "Utf" <-- thrown in D:\wamp\www\mojekarte-dev-krv\smarty\sysplugins\smarty_internal_templatecompilerbase.php on line 51

Then i tried with a function toUtf (without class, namespace...) and replace |Utf::toUtf8} with |toUtf} no exception is returned.

Tested on: 3.1.18

Thanks
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5067
Location: Hamburg / Germany

PostPosted: Fri May 23, 2014 3:51 pm    Post subject: Reply with quote

Use registerPlugin() to register your static method as modifier.

See http://www.smarty.net/docs/en/api.register.plugin.tpl
Back to top
View user's profile Send private message
Jerc
Smarty Rookie


Joined: 26 Jan 2010
Posts: 30
Location: Slovenia / Ljubljana

PostPosted: Mon May 26, 2014 5:38 am    Post subject: Reply with quote

It's working!
Thanks.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Bugs 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