1

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.

Ashleigh
  • 35
  • 7
  • Are you trying to output the PHP as text, or execute the PHP inside a PHP variable? Either way, you shouldn't be doing it. Your internal code should never be output to the end user, and you can't execute PHP inside of a string like that. – Lin Meyer Jun 09 '15 at 15:21
  • In this context just outputting text. I did eventually figure out that it was MUCH better to bind PHP values to mustaches variables, and pass in strings, rather than passing PHP code. – Ashleigh Jun 12 '15 at 01:54

0 Answers0