소스 검색

Fix for missing child context in sections.

Justin Hileman 15 년 전
부모
커밋
5a819a33da
4개의 변경된 파일22개의 추가작업 그리고 1개의 파일을 삭제
  1. 5 1
      Mustache.php
  2. 13 0
      examples/child_context/ChildContext.php
  3. 2 0
      examples/child_context/child_context.mustache
  4. 2 0
      examples/child_context/child_context.txt

+ 5 - 1
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;
 			}

+ 13 - 0
examples/child_context/ChildContext.php

@@ -0,0 +1,13 @@
+<?php
+
+class ChildContext extends Mustache {
+	public $parent = array(
+		'child' => 'child works',
+	);
+	
+	public $grandparent = array(
+		'parent' => array(
+			'child' => 'grandchild works',
+		),
+	);
+}

+ 2 - 0
examples/child_context/child_context.mustache

@@ -0,0 +1,2 @@
+<h1>{{#parent}}{{child}}{{/parent}}</h1>
+<h2>{{#grandparent}}{{#parent}}{{child}}{{/parent}}{{/grandparent}}</h2>

+ 2 - 0
examples/child_context/child_context.txt

@@ -0,0 +1,2 @@
+<h1>child works</h1>
+<h2>grandchild works</h2>