Skip to content

Commit

Permalink
Fix the last couple of regressions with section rendering.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed Jun 13, 2011
1 parent f95f8c0 commit e452b4c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions Mustache.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ protected function _renderTemplate($template) {
if ($section = $this->_findSection($template)) {
list($before, $type, $tag_name, $content, $after) = $section;

$replace = '';
$renderedContent = '';
$val = $this->_getVariable($tag_name);
switch($type) {
// inverted section
case '^':
if (empty($val)) {
$replace .= $content;
$renderedContent = $this->_renderTemplate($content);
}
break;

Expand All @@ -229,22 +229,22 @@ protected function _renderTemplate($template) {
if ($this->_varIsIterable($val)) {
foreach ($val as $local_context) {
$this->_pushContext($local_context);
$replace .= $this->_renderTemplate($content);
$renderedContent .= $this->_renderTemplate($content);
$this->_popContext();
}
} else if ($val) {
if (is_array($val) || is_object($val)) {
$this->_pushContext($val);
$replace .= $this->_renderTemplate($content);
$renderedContent = $this->_renderTemplate($content);
$this->_popContext();
} else {
$replace .= $content;
$renderedContent = $this->_renderTemplate($content);
}
}
break;
}

return $this->_renderTags($before) . $replace . $this->_renderTemplate($after);
return $this->_renderTags($before) . $renderedContent . $this->_renderTemplate($after);
}

return $this->_renderTags($template);
Expand All @@ -268,9 +268,7 @@ protected function _prepareSectionRegEx($otag, $ctag) {
}

/**
* Extract a section from $template.
*
* This is a helper function to find sections needed by _renderSections.
* Extract the first section from $template.
*
* @access protected
* @param string $template
Expand Down Expand Up @@ -566,7 +564,7 @@ protected function _renderTag($modifier, $tag_name, $leading, $trailing) {
case '#':
case '^':
case '/':
// remove any leftovers from _renderSections
// remove any leftover section tags
return $leading . $trailing;
break;
default:
Expand Down

0 comments on commit e452b4c

Please sign in to comment.