Suppress else when rendering empty block defaults.

This commit is contained in:
Justin Hileman
2017-06-28 23:20:21 -07:00
parent bd39afffef
commit 44baf86426
+9 -3
View File
@@ -240,10 +240,11 @@ class Mustache_Compiler
$blockFunction = $context->findInBlock(%s);
if (is_callable($blockFunction)) {
$buffer .= call_user_func($blockFunction, $context);
} else {%s
}
%s}
';
const BLOCK_VAR_ELSE = '} else {%s';
/**
* Generate Mustache Template inheritance block variable PHP source.
*
@@ -261,7 +262,12 @@ class Mustache_Compiler
{
$id = var_export($id, true);
return sprintf($this->prepare(self::BLOCK_VAR, $level), $id, $this->walk($nodes, $level));
$else = $this->walk($nodes, $level);
if ($else !== '') {
$else = sprintf($this->prepare(self::BLOCK_VAR_ELSE, $level + 1, false, true), $else);
}
return sprintf($this->prepare(self::BLOCK_VAR, $level), $id, $else);
}
const BLOCK_ARG = '$blocksContext[%s] = array($this, \'block%s\');';