Preloading templates in a custom BB code PHP callback

Chris D

XenForo developer
Staff member
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?
 
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).
 
The formatter is already created and passed to the callback so I've just done it using the template_create event.

Thanks Mike
 
Top Bottom