|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
johndoe1395 Smarty n00b
Joined: 13 Apr 2013 Posts: 4
|
Posted: Mon Nov 17, 2014 11:14 pm Post subject: Smarty and plugins |
|
|
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 |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Nov 18, 2014 7:04 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Nov 21, 2014 1:33 am Post subject: |
|
|
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 |
|
johndoe1395 Smarty n00b
Joined: 13 Apr 2013 Posts: 4
|
Posted: Sun Nov 23, 2014 2:53 am Post subject: |
|
|
Thank you both for your input |
|
Back to top |
|
|
|
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
|