title: Assign smarty variable during template time
body: <p>In a smarty template I call a user defined function, as a modifier like that:</p>
  
  <pre><code>{"myArray"|assignArray}
  </code></pre>
  
  <p>my user defined function in php looks as:</p>
  
  <pre><code>function smarty_modifier_assignArray($str)
  {
    global $smarty;
    if ($str=="myArray") 
    {
      // it is not constant in real, but comes from a mysql query
      $all = array( array("foo","joe")), array("green", "blue"));
      $smarty-&amp;gt;assign($str,$all);
    }
    return null;
  }
  </code></pre>
  
  <p>My purpose is that loading "myArray" from mysql is expensive, and if my template do not need that
  array, I don't want to load it. My template follows as:</p>
  
  <pre><code>{"myArray"|assignArray}
  {foreach from=$myArray item=r}
    {$r[0]}
  {/foreach}
  </code></pre>
  
  <p>The problem is, that in the foreach I can't see $myArray (or it is empty). I read in the smarty forum  (v3.x, <a href="http://www.smarty.net/forums/viewtopic.php?p=77671" rel="nofollow">http://www.smarty.net/forums/viewtopic.php?p=77671</a> ) that for speed optimalization the variables are copied to the template space, so after starting a template, one can not assign new variables onto that. Sadly it seems true. I suppose using template {assign ...} I still could do that, but I was not able to generate dynamical multi-level arrays into that {assign ...} :(</p>
  
  <p>What should I do? Any ideas?</p>