From 6c2b85c36b49386579df1e8f7266473426edea72 Mon Sep 17 00:00:00 2001 From: jwronsky Date: Fri, 17 Feb 2012 23:11:54 +0100 Subject: [PATCH] Dot notation with numeric indexes fix. --- Mustache.php | 2 +- examples/dot_notation/DotNotation.php | 5 +++-- examples/dot_notation/dot_notation.mustache | 3 ++- examples/dot_notation/dot_notation.txt | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Mustache.php b/Mustache.php index 6729509..bdc6237 100644 --- a/Mustache.php +++ b/Mustache.php @@ -773,7 +773,7 @@ class Mustache { $first = array_shift($chunks); $ret = $this->_findVariableInContext($first, $this->_context); - while ($next = array_shift($chunks)) { + foreach ($chunks as $next) { // Slice off a chunk of context for dot notation traversal. $c = array($ret); $ret = $this->_findVariableInContext($next, $c); diff --git a/examples/dot_notation/DotNotation.php b/examples/dot_notation/DotNotation.php index 0274e19..7dd0a4e 100644 --- a/examples/dot_notation/DotNotation.php +++ b/examples/dot_notation/DotNotation.php @@ -9,10 +9,11 @@ class DotNotation extends Mustache { public $person = array( 'name' => array('first' => 'Chris', 'last' => 'Firescythe'), 'age' => 24, + 'hobbies' => array('Cycling', 'Fishing'), 'hometown' => array( - 'city' => 'Cincinnati', + 'city' => 'Cincinnati', 'state' => 'OH', - ) + ), ); public $normal = 'Normal'; diff --git a/examples/dot_notation/dot_notation.mustache b/examples/dot_notation/dot_notation.mustache index 0566867..0135a2a 100644 --- a/examples/dot_notation/dot_notation.mustache +++ b/examples/dot_notation/dot_notation.mustache @@ -1,4 +1,5 @@ * {{person.name.first}} {{person.name.last}} * {{person.age}} +* {{person.hobbies.0}}, {{person.hobbies.1}} * {{person.hometown.city}}, {{person.hometown.state}} -* {{normal}} \ No newline at end of file +* {{normal}} diff --git a/examples/dot_notation/dot_notation.txt b/examples/dot_notation/dot_notation.txt index f8cf1fa..e5c1ed9 100644 --- a/examples/dot_notation/dot_notation.txt +++ b/examples/dot_notation/dot_notation.txt @@ -1,4 +1,5 @@ * Chris Firescythe * 24 +* Cycling, Fishing * Cincinnati, OH -* Normal \ No newline at end of file +* Normal