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

Template Caching?

Discussion in 'XenForo Development Discussions' started by Renari, Jan 1, 2013.

  1. Renari

    Renari Member

    I have a while loop generating a list of users like so.
    while ($user $query->fetch()) {
    $params $template->getParams();
    $hookParams += $user;
    $params += $hookParams;
    $content .= $template->create('template'$params);
    However when this is being output whoever the first user in the query is, it will output that template for the first user the amount of times the while loop would have run. Is this problem related to template caching?
  2. Luke F

    Luke F Well-Known Member

    I believe this is due to the shorthand += operator taking the original in case of conflicts when merging arrays, try $hookParams = $user + $hookParams and $params = $hookParams + $params

    Also a side note, I recommend having a PHP opcode cache and enabling the 'templates as files' option when using a lot of $template->create's like that, otherwise it queries the database and parses the template over and over again each time
  3. Renari

    Renari Member

    Thanks, you were right also thanks for the suggestion on improving the code I've never used an opcode cache before and I'll read up on it. I wasn't aware that += prioritized the original array, rather I believed it to function the opposite.
  4. Luke F

    Luke F Well-Known Member

    Yeah it's very unintuitive for the array before the + to take priority, typical PHP :p

Share This Page