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

preloadTemplate, what it do?

Discussion in 'XenForo Development Discussions' started by Jake Bunce, Feb 1, 2012.

  1. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I am trying to understand the low level function of preloadTemplate. I found code examples, such as Kier's post here:

    http://xenforo.com/community/threads/suggestion-list-of-xenforo-com-custom-edits.17157/#post-224952

    But I don't understand exactly how it works and when it is appropriate.

    In my specific situation I have a navigation_tabs listener that renders a template:

    Code:
    				$template = new XenForo_Template_Public('nat_childlinks', array(
    					'firstChildNodes' => $firstChildNodes,
    					'selected' => $selectedTabId == 'nodetab' . $nodeTab['node_id']
    				));
    				$childLinks = $template->render();
    
    I am wondering if I should be preloading this template.
     
  2. Mythotical

    Mythotical Well-Known Member

    When dealing with navigation I find that preloading is not necessary. When using template hooks preloading is optimal hence creating a savvy looking file and making the loading of the template faster considering the preload from what I understand cache's the template.
     
  3. Onimua

    Onimua Well-Known Member

    I've found that if you're using template hooks, look at the query count. If it increases by one it should be preloaded and if there's no change in the count you could leave it as-is.

    Now whether or not you should preload in all instances is something I'm unsure of. I don't think it's necessary as it's already called/cached (the extra query to fetch that particular template not being needed).
     
    EQnoble, Mike and ragtek like this.
  4. Mythotical

    Mythotical Well-Known Member

    Agreed Onimua, didn't think about the query count.
     
  5. EQnoble

    EQnoble Well-Known Member


    Thank you...this topic of this thread makes sense to me now...and the first line is worded in a way that if I need to remember this sometime down the road ....I will recall this thread.
     

Share This Page