Separate stacks are necessary for blocks to be resolved independently of variables. Renamed parent_* to block_*.

This commit is contained in:
Dan Miller
2014-04-08 21:02:23 +00:00
parent 63b835bd09
commit af8a62c5e2
8 changed files with 82 additions and 31 deletions
+13 -2
View File
@@ -15,6 +15,7 @@
class Mustache_Context
{
private $stack = array();
private $block_stack = array();
/**
* Mustache rendering Context constructor.
@@ -38,6 +39,11 @@ class Mustache_Context
array_push($this->stack, $value);
}
public function pushBlockContext($value)
{
array_push($this->block_stack, $value);
}
/**
* Pop the last Context frame from the stack.
*
@@ -48,6 +54,11 @@ class Mustache_Context
return array_pop($this->stack);
}
public function popBlockContext()
{
return array_pop($this->block_stack);
}
/**
* Get the last Context frame.
*
@@ -120,9 +131,9 @@ class Mustache_Context
return $value;
}
public function findFromParent($id)
public function findInBlock($id)
{
foreach($this->stack as $context) {
foreach($this->block_stack as $context) {
if (is_array($context) && array_key_exists($id, $context)) {
return $context[$id];
}