MyBB Community Forums

Full Version: updating $templatelist from within a plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to reduce the queries in the plugins I am writing/updating and am trying to update $templatelist variable before the template outputs start.

I have tried putting

$templatelist .= "CSV list of template names";

at both the top of the plugin under the run_hooks code as well as inside a global_start function and I have global'd $templatelist in my function.

however, it does not matter as the debug shows the templates I am using are not cached.

Though one template is listed in the cached set AND in the uncached set.

How do I get a plugin to cache template names before they are used?
I guess something like this;
$templates->cache["TEMPLATE NAME GOES HERE"]
actually i figured it out. since I need the templates in global_start in order to make new output for the header to use, there is no $theme array defined yet so non-default templates (sid <> -2 or -1) are not cached.

so ANY template that is eval'd in a plugin before global_end will NOT use the template cache and will create one query for each template being eval'd.

The workaround (not really a solution in my opinion) is to use placeholders in the templates modified by global_start and then in global_end eval the new templates and then do a str_replace in the already eval'd template variables.

However, this requires more work for plugin authors and one extra hook to be run for these cases.

example:
Instead of inserting {$myoutput} into a template that is part of the header, you would put <--myoutput--> and then in global_start populate a global'd $myoutput and in global_end do a str_replace("<--myoutput-->", $myoutput, $header)

its not super hard to do this, but it does make it more difficult to track edits during development.
(2011-10-13, 06:40 PM)Yaldaram Wrote: [ -> ]I guess something like this;
$templates->cache["TEMPLATE NAME GOES HERE"]

nope, wont work since $theme is not yet defined and the template set id is not available.
(2011-10-13, 06:04 PM)pavemen Wrote: [ -> ]I am trying to reduce the queries in the plugins I am writing/updating and am trying to update $templatelist variable before the template outputs start.

I have tried putting

$templatelist .= "CSV list of template names";

at both the top of the plugin under the run_hooks code as well as inside a global_start function and I have global'd $templatelist in my function.

however, it does not matter as the debug shows the templates I am using are not cached.

Though one template is listed in the cached set AND in the uncached set.

How do I get a plugin to cache template names before they are used?

Just curious as to how you're debugging to see this info. I too would like to see if my templates are being cached or not.
wow, old thread. just use the default debug output that admins can see. you can set it to be output via the ACP configuration > settings page
Oh, cool! Thanks. I missed that!