Skip to content

Instantly share code, notes, and snippets.

@jazzdan
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jazzdan/10675121 to your computer and use it in GitHub Desktop.
Save jazzdan/10675121 to your computer and use it in GitHub Desktop.
<?php
require 'src/Mustache/Autoloader.php';
Mustache_Autoloader::register();
$m = new Mustache_Engine([
'partials' => [
'header' => '<title>{{$title}}Default title{{/title}}</title>',
'base' => '<html>{{$header}}{{/header}}{{$content}}{{/content}}</html>'
],
]);
$tpl = <<<'EOS'
{{<base}}{{$header}}{{<header}}{{$title}}My page title{{/title}}{{/header}}{{/header}}{{/base}}
EOS;
echo $m->render($tpl, []);
outputs:
<html>&lt;title&gt;My page title&lt;/title&gt;</html>
diff --git a/src/Mustache/Compiler.php b/src/Mustache/Compiler.php
index dcc9469..44f877b 100644
--- a/src/Mustache/Compiler.php
+++ b/src/Mustache/Compiler.php
@@ -213,7 +213,7 @@ class Mustache_Compiler
const BLOCK_VAR = '
$value = $this->resolveValue($context->%s(%s), $context, $indent);
if($value && !is_array($value) && !is_object($value)) {
- $buffer .= %s;
+ $buffer .= $value;
} else {
%s
}
@@ -223,9 +223,8 @@ class Mustache_Compiler
{
$method = 'findInBlock';
$id_str = var_export($id, true);
- $value = $this->getEscape();
- return sprintf($this->prepare(self::BLOCK_VAR, $level), $method, $id_str, $value, $this->walk($nodes, 2));
+ return sprintf($this->prepare(self::BLOCK_VAR, $level), $method, $id_str, $this->walk($nodes, 2));
}
Then it outputs:
<html><title>My page title</title></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment