Merge branch 'hotfix/0.1.1'
This commit is contained in:
+16
-1
@@ -142,13 +142,17 @@ class Mustache {
|
||||
|
||||
// regular section
|
||||
case '#':
|
||||
if (is_array($val)) {
|
||||
if ($this->varIsIterable($val)) {
|
||||
foreach ($val as $local_context) {
|
||||
$replace .= $this->_render($content, $this->getContext($context, $local_context));
|
||||
}
|
||||
} else if ($val) {
|
||||
if (is_array($val) || is_object($val)) {
|
||||
$replace .= $this->_render($content, $this->getContext($context, $val));
|
||||
} else {
|
||||
$replace .= $content;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -387,6 +391,17 @@ class Mustache {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given $var should be iterated (i.e. in a section context).
|
||||
*
|
||||
* @access protected
|
||||
* @param mixed $var
|
||||
* @return bool
|
||||
*/
|
||||
protected function varIsIterable($var) {
|
||||
return is_object($var) || (is_array($var) && !array_diff_key($var, array_keys(array_keys($var))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a string to be used in a regular expression.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class ChildContext extends Mustache {
|
||||
public $parent = array(
|
||||
'child' => 'child works',
|
||||
);
|
||||
|
||||
public $grandparent = array(
|
||||
'parent' => array(
|
||||
'child' => 'grandchild works',
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<h1>{{#parent}}{{child}}{{/parent}}</h1>
|
||||
<h2>{{#grandparent}}{{#parent}}{{child}}{{/parent}}{{/grandparent}}</h2>
|
||||
@@ -0,0 +1,2 @@
|
||||
<h1>child works</h1>
|
||||
<h2>grandchild works</h2>
|
||||
Reference in New Issue
Block a user