Cant escape PHP code in mustache variables

843 views Asked by At

I'm using the PHP version of mustache, and also patternLab - which I think also uses the PHP version of mustache.

example 1 : PHP version of mustache I've also tried using the escape option, to no avail Using triple {{{}}} doesn't work either

<?php
$test = "meow";
$meow = '<?php echo $test?>';

$mm = new Mustache_Engine(array(
    'escape' => function($text) { return $text; }
));

echo $mm->render('Hello, {{cat}}!', array('cat' => $meow)); // "Hello, meow!"
?>

this will render:

<!--?php echo $test?--> 

example patternlab:

JSON file

{
    "echotest" : "<?php echo $test; ?>"
}

mustache file

<h2>{{{echotest}}}</h2>

outputs:

<h2><!--?php echo $test; ?--></h2>

Both times, the code is commented out, and not actually rendered. This is not what I want ;)

Maybe I'm going about this in the entirely wrong way, but I would like to have PHP in my mustache files, so that code can be used later on in my process, when I require these mustache files in a PHP project.

0

There are 0 answers