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

override of custom functions

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


Joined: 11 Aug 2014
Posts: 2

PostPosted: Mon Aug 11, 2014 9:04 pm    Post subject: override of custom functions Reply with quote

Hi all, I am new to Smarty but looking forward to using it a lot!

I have added a second plugins directory to the config.

Is it possible to have functions in there that override functions in the first config directory? For example, several functions are OK, but smarty_function_html_table needs a lot of rewriting.

Later on I might want to have different layouts in my project. Some templates would need overriding, but several would not, so Smarty would have to fall back on a previous plugins directory.

Is that possible? I copied and edited smarty_function_html_table into my own plugins folder and added that folder to Smarty in three ways (1. add it to the end of the array, 2. add it to the start of the array, 3. use the addPluginsDir function) but I only got the original smarty_function_html_table function.

Thanks!
Jerry
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1503

PostPosted: Mon Aug 11, 2014 9:48 pm    Post subject: Re: override of custom functions Reply with quote

jerry1970 wrote:
I have added a second plugins directory to the config.

Is it possible to have functions in there that override functions in the first config directory?

Of course. All you have to do is to not ADD, but SET plugins directory.
Then you can control the order, in which they are searched.

Quote:
For example, several functions are OK, but smarty_function_html_table needs a lot of rewriting.

Patches thoughtfully considered.

Quote:
Later on I might want to have different layouts in my project. Some templates would need overriding, but several would not, so Smarty would have to fall back on a previous plugins directory.

Read documentation, please. It is all written here, in plain english.
Back to top
View user's profile Send private message
jerry1970
Smarty n00b


Joined: 11 Aug 2014
Posts: 2

PostPosted: Tue Aug 12, 2014 5:10 am    Post subject: Reply with quote

I did this:
Code:
        $pluginsDirs = $smarty->getPluginsDir();
        // add before current plugins directory:
        array_unshift($pluginsDirs, 'my/own/plugins');
        $smarty->setPluginsDir($pluginsDirs);


and I tried this:
Code:
        $pluginsDirs = $smarty->getPluginsDir();
        // add after current plugins directory:
        $pluginsDirs[] = 'my/own/plugins';
        $smarty->setPluginsDir($pluginsDirs);


but this TPL:
Code:
{html_table loop=$data}


gives me the original html_table function, not my edited version in my/own/plugins. I tried to make a new function in my own plugins directory and that works, so Smarty can find the directory.

Of course I read the documentation, I came here because it doesn't work for me.

I must be doing something wrong...
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1503

PostPosted: Tue Aug 12, 2014 3:05 pm    Post subject: Reply with quote

jerry1970 wrote:
I did this:
Code:
        $pluginsDirs = $smarty->getPluginsDir();
        // add before current plugins directory:
        array_unshift($pluginsDirs, 'my/own/plugins');
        $smarty->setPluginsDir($pluginsDirs);

WJFFM

Quote:
and I tried this:
Code:
        $pluginsDirs = $smarty->getPluginsDir();
        // add after current plugins directory:
        $pluginsDirs[] = 'my/own/plugins';
        $smarty->setPluginsDir($pluginsDirs);

This will append, not prepend your plugins.

Quote:
but this TPL:
Code:
{html_table loop=$data}


gives me the original html_table function, not my edited version in my/own/plugins. I tried to make a new function in my own plugins directory and that works, so Smarty can find the directory.

Of course I read the documentation, I came here because it doesn't work for me.

I must be doing something wrong...

Works just fine for me.
I hope you did set Smarty::force_compile to true before running your tests.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Tue Aug 12, 2014 5:02 pm    Post subject: Reply with quote

Yes, a change of the plugins_dir configuration as no effect on already compiled or cached templates.

Use $smarty->force_compile = true;
or delete existing compiled and cache files after the change of configuration.

For performance reason Smarty does cache the file path of plugin files at compile time.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins 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