From 5a819a33da26e79e7d4fe05368327c3d58714c05 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 26 Apr 2010 21:49:54 -0400 Subject: [PATCH] Fix for missing child context in sections. --- Mustache.php | 6 +++++- examples/child_context/ChildContext.php | 13 +++++++++++++ examples/child_context/child_context.mustache | 2 ++ examples/child_context/child_context.txt | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 examples/child_context/ChildContext.php create mode 100644 examples/child_context/child_context.mustache create mode 100644 examples/child_context/child_context.txt diff --git a/Mustache.php b/Mustache.php index 5cd1137..e1f69cd 100644 --- a/Mustache.php +++ b/Mustache.php @@ -147,7 +147,11 @@ class Mustache { $replace .= $this->_render($content, $this->getContext($context, $local_context)); } } else if ($val) { - $replace .= $content; + if (is_array($val) || is_object($val)) { + $replace .= $this->_render($content, $this->getContext($context, $val)); + } else { + $replace .= $content; + } } break; } diff --git a/examples/child_context/ChildContext.php b/examples/child_context/ChildContext.php new file mode 100644 index 0000000..b652356 --- /dev/null +++ b/examples/child_context/ChildContext.php @@ -0,0 +1,13 @@ + 'child works', + ); + + public $grandparent = array( + 'parent' => array( + 'child' => 'grandchild works', + ), + ); +} \ No newline at end of file diff --git a/examples/child_context/child_context.mustache b/examples/child_context/child_context.mustache new file mode 100644 index 0000000..e1f2ebc --- /dev/null +++ b/examples/child_context/child_context.mustache @@ -0,0 +1,2 @@ +

{{#parent}}{{child}}{{/parent}}

+

{{#grandparent}}{{#parent}}{{child}}{{/parent}}{{/grandparent}}

\ No newline at end of file diff --git a/examples/child_context/child_context.txt b/examples/child_context/child_context.txt new file mode 100644 index 0000000..cfb76bf --- /dev/null +++ b/examples/child_context/child_context.txt @@ -0,0 +1,2 @@ +

child works

+

grandchild works

\ No newline at end of file