• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Preloading templates in a custom BB code PHP callback

Chris D

XenForo developer
Staff member
#1
In a custom BB code PHP callback I am creating, I call a template and currently this call to the template is generating an additional template query per page.

I have tried:
PHP:
$formatter->getView()->preLoadTemplate('my_template');
and:
PHP:
$template->preloadTemplate('my_template');
Neither preload the template as I would expect.

I can presumably do this via the template_create code event, but it seems like this should work. Can anyone suggest anything I might have missed?
 

Mike

XenForo developer
Staff member
#2
Well, it will still cause one query, but chances are it's simply done too late. You'd need to do it when creating the formatter most likely (to properly ensure it's cached).
 

Chris D

XenForo developer
Staff member
#3
The formatter is already created and passed to the callback so I've just done it using the template_create event.

Thanks Mike