diff --git a/src/Mustache/Compiler.php b/src/Mustache/Compiler.php
index c38ca43..c13e60f 100644
--- a/src/Mustache/Compiler.php
+++ b/src/Mustache/Compiler.php
@@ -188,9 +188,14 @@ class Mustache_Compiler
$buffer = \'\';
if (%s) {
$source = %s;
- $buffer .= $this->mustache
- ->loadLambda((string) call_user_func($value, $source, $this->lambdaHelper)%s)
- ->renderInternal($context);
+ $result = call_user_func($value, $source, $this->lambdaHelper);
+ if (strpos($result, \'{{\') === false) {
+ $buffer .= $result;
+ } else {
+ $buffer .= $this->mustache
+ ->loadLambda((string) $result%s)
+ ->renderInternal($context);
+ }
} elseif (!empty($value)) {
$values = $this->isIterable($value) ? $value : array($value);
foreach ($values as $value) {
diff --git a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php
index 0919656..078988b 100644
--- a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php
+++ b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php
@@ -71,6 +71,35 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework
$dracula->name = 'Dracula';
$this->assertEquals('Count Dracula', $tpl->render($dracula));
}
+
+ public function testPassthroughOptimization()
+ {
+ $mustache = $this->getMock('Mustache_Engine', array('loadLambda'));
+ $mustache->expects($this->never())
+ ->method('loadLambda');
+
+ $tpl = $mustache->loadTemplate('{{#wrap}}NAME{{/wrap}}');
+
+ $foo = new Mustache_Test_Functional_Foo;
+ $foo->wrap = array($foo, 'wrapWithEm');
+
+ $this->assertEquals('NAME', $tpl->render($foo));
+ }
+
+ public function testWithoutPassthroughOptimization()
+ {
+ $mustache = $this->getMock('Mustache_Engine', array('loadLambda'));
+ $mustache->expects($this->once())
+ ->method('loadLambda')
+ ->will($this->returnValue($mustache->loadTemplate('{{ name }}')));
+
+ $tpl = $mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
+
+ $foo = new Mustache_Test_Functional_Foo;
+ $foo->wrap = array($foo, 'wrapWithEm');
+
+ $this->assertEquals('' . $foo->name . '', $tpl->render($foo));
+ }
}
class Mustache_Test_Functional_Foo