|
@@ -424,7 +424,7 @@ class Mustache {
|
|
|
* @return string
|
|
* @return string
|
|
|
*/
|
|
*/
|
|
|
protected function _renderPartial($tag_name, &$context) {
|
|
protected function _renderPartial($tag_name, &$context) {
|
|
|
- $view = new self($this->_getPartial($tag_name), $context, $this->_partials);
|
|
|
|
|
|
|
+ $view = new self($this->_getPartial($tag_name), $this->_flattenContext($context), $this->_partials);
|
|
|
$view->_otag = $this->_otag;
|
|
$view->_otag = $this->_otag;
|
|
|
$view->_ctag = $this->_ctag;
|
|
$view->_ctag = $this->_ctag;
|
|
|
return $view->render();
|
|
return $view->render();
|
|
@@ -458,8 +458,8 @@ class Mustache {
|
|
|
*
|
|
*
|
|
|
* @access protected
|
|
* @access protected
|
|
|
* @param array $context
|
|
* @param array $context
|
|
|
- * @param mixed $local_context
|
|
|
|
|
- * @return void
|
|
|
|
|
|
|
+ * @param array $local_context
|
|
|
|
|
+ * @return array
|
|
|
*/
|
|
*/
|
|
|
protected function _getContext(&$context, &$local_context) {
|
|
protected function _getContext(&$context, &$local_context) {
|
|
|
$ret = array();
|
|
$ret = array();
|
|
@@ -470,6 +470,45 @@ class Mustache {
|
|
|
return $ret;
|
|
return $ret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Prepare a new (flattened) context.
|
|
|
|
|
+ *
|
|
|
|
|
+ * This is used to create a view object or array for rendering partials.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @access protected
|
|
|
|
|
+ * @param array &$context
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ * @throws MustacheException
|
|
|
|
|
+ */
|
|
|
|
|
+ protected function _flattenContext(&$context) {
|
|
|
|
|
+ $keys = array_keys($context);
|
|
|
|
|
+ $first = $context[$keys[0]];
|
|
|
|
|
+
|
|
|
|
|
+ if ($first instanceof Mustache) {
|
|
|
|
|
+ $ret = clone $first;
|
|
|
|
|
+ unset($keys[0]);
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($keys as $name) {
|
|
|
|
|
+ foreach ($context[$name] as $key => $val) {
|
|
|
|
|
+ $ret->$key =& $val;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (is_array($first)) {
|
|
|
|
|
+ $ret = array();
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($keys as $name) {
|
|
|
|
|
+ foreach ($context[$name] as $key => $val) {
|
|
|
|
|
+ $ret[$key] =& $val;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new MustacheException('Unknown root context type.');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $ret;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Get a variable from the context array.
|
|
* Get a variable from the context array.
|
|
|
*
|
|
*
|