Closed maan1234 closed 7 years ago
@maan1234 I suggest to add break points in EachHelper before and after each to see if you can figure out what happens to context and probably debug it.
@everplays Thank you for the reply. I am not an hardcore debugger. var_dump
is my debug-tool.
The context changes because of the #when helper. This does not happen with the build-in #if helper.
I am only using the library to add Handlebars templates in my project and not familiar with the libraries inner workings, so it is hard for me to debug it.
protected 'stack' =>
array (size=5)
0 =>
array (size=2)
'data' =>
array (size=4)
...
'finish' => string 'ok' (length=2)
1 => int 0 // = new at end of #each helper
2 => int 1 // = new
3 => int 2 // = new
4 => int 3 // = new
It see that there are two pushes to the Context. One by #each and one by #when (by calling ['inverse']() or ['fn']() ). There is only one pop by #each. So it seems ['inverse']() or ['fn']() fail to clear their push() to the stack.
My guess it that Handlebars.php line 321 and line 362 should be changed from:
if ($defined) {
$inContext->pop();
}
to
if (!$defined) {
$inContext->pop();
}
So the push and pop are both applied in the same condition.
@maan1234 indeed that was the problem. I have added some test coverage for it as well. Thanks for reporting and debugging it.
I have stumbled on a problem where the
#when
-helper seems to clear all variables, if it is nested in a#each
. The code to replicate the problem is below. I am using the latest version of the library.I am new to this Handlebars library, so if there is something wrong with my way of coding, a little push in the right direction is also greatly appreciated.