using array keys instead of iteration over context for creating subcontext arrays. this fixes incorrect context stacks in recursive partials.

This commit is contained in:
Justin Hileman
2010-05-22 20:40:01 -04:00
parent 95abf1d52b
commit 0893a7d39d
+6 -6
View File
@@ -92,7 +92,6 @@ class Mustache {
$this->_otag = '{{'; $this->_otag = '{{';
$this->_ctag = '}}'; $this->_ctag = '}}';
$this->_localPragmas = null; $this->_localPragmas = null;
if ($keys = array_keys($this->_context)) { if ($keys = array_keys($this->_context)) {
if ($this->_context[$keys[0]] instanceof Mustache) { if ($this->_context[$keys[0]] instanceof Mustache) {
$this->_context[$keys[0]] =& $this; $this->_context[$keys[0]] =& $this;
@@ -475,8 +474,8 @@ class Mustache {
protected function _pushContext(&$local_context) { protected function _pushContext(&$local_context) {
$new = array(); $new = array();
$new[] =& $local_context; $new[] =& $local_context;
foreach ($this->_context as $view) { foreach (array_keys($this->_context) as $key) {
$new[] =& $view; $new[] =& $this->_context[$key];
} }
$this->_context = $new; $this->_context = $new;
} }
@@ -491,9 +490,10 @@ class Mustache {
protected function _popContext() { protected function _popContext() {
$new = array(); $new = array();
array_shift($this->_context); $keys = array_keys($this->_context);
foreach ($this->_context as $view) { array_shift($keys);
$new[] =& $view; foreach ($keys as $key) {
$new[] =& $this->_context[$key];
} }
$this->_context = $new; $this->_context = $new;
} }