Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty and plugins

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
johndoe1395
Smarty n00b


Joined: 13 Apr 2013
Posts: 4

PostPosted: Mon Nov 17, 2014 11:14 pm    Post subject: Smarty and plugins Reply with quote

Hello
I have an application with plugin support. The user can easily add configurations for the plugins in the backend and give them names which then can be referenced in the templates like this:
{plugin name="plugin_name" config="config_name"}

The thing is, registering a custom function for "plugin" which will run everytime the parser finds the "{plugin}" tag and then loads the config from db is slow since there might be multiple plugins in a page so it will run a query for each plugin it finds.

How would one go about to solve this problem? That is, how to collect all {plugin} tags that are in a template so I can load all configurations in a single query so when the {plugin} tag is reached, it can gets its config from that preloaded array?

I know this could be remedied with caching but at the moment the application is not optimized for caching and it would mess a lot of stuff up.

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


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

PostPosted: Tue Nov 18, 2014 7:04 pm    Post subject: Reply with quote

The only way I can think of is to read the template source and use preg_match_all to grep the required information.
That is relatively easy for the main template source but is getting complex if you have your plugins also inside subtemplates.

Also extra reading of source files may not save execution time at the end.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Nov 21, 2014 1:33 am    Post subject: Reply with quote

The only real answer is caching.
You may do a little loop around to put all {plugin} calls into sub-templates and cache them separately.
Back to top
View user's profile Send private message
johndoe1395
Smarty n00b


Joined: 13 Apr 2013
Posts: 4

PostPosted: Sun Nov 23, 2014 2:53 am    Post subject: Reply with quote

Thank you both for your input Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    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