On Thu, 9 Dec 1999, Gerald Richter wrote:

> If I had understand you right, the first call via execute to your template
> works and the second not, right?
> 
> That's not a bug! Embperl cleans up all your global variables inside your
> page after every request. $vars in your template is such a global variable,
> so Embperl undef it and therfore the content gets lost and it won't work the
> second time.

Oddly, that's not quite what is happening.  The content isn't lost
altogether, else the simple join() I include wouldn't work either.

Moreover, even if I re-initialize the data passed into my printTemplate()
routine, the second call is still using some of the old data.  

Note that this issue is only appearing on array data, and only in the
foreach command.  

When I call the template containing a [$ foreach $] for the second time,
every value in that array *in the foreach loop* is returned as the last
value of the array, as called the first time around.

Here's a little test.  Try putting this in a template, and Executing on it
twice by the same process.  No input data, no parameters, just the
template on it's own.

  [- @array = (1, 2, 3) -]
  [+ join(",", @array) +]
  [$ foreach $arrayElement (@array) $]
  [+ $arrayElement +]
  [$ endforeach $]

That's it.  The first time it will print (I stripped out the newlines):

1,2,3
1
2
3

The second time it will print:

1,2,3
3
3
3


Apparently, this has nothing to do with Safe() or anything else.  Just
that the value given to $arrayElement in the [$ foreach $] doesn't seem to
be correct on subsequent executions, that's all.

Sorry to be sticking with this one, but I want to hear from just one
person that I'm not losing my mind.  I really do appreciate the help,
though.  :)

-DeWitt


Reply via email to