1. 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

Discussion in 'XenForo Development Discussions' started by Chris D, Feb 7, 2014.

  1. Chris D

    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?
     
  2. Mike

    Mike XenForo Developer Staff Member

    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).
     
    Divvens likes this.
  3. Chris D

    Chris D XenForo Developer Staff Member

    The formatter is already created and passed to the callback so I've just done it using the template_create event.

    Thanks Mike
     

Share This Page