0
我想給一個變量傳遞給一個函數:PHP鬍子傳遞變量的函數
{{#myFunc}}{{someVar}}{{/myFunction}}
這是我的引擎:
$options = [
'helpers' => [
'myFunc' => function($value) {
// This works
return 'got value: ' . $value;
// This does not work
return SomeClass::reformat($value);
// It passes "{{someVar}}" to the method, not the value
// var_dump shows
var_dump($value); // '{{someVar}}'
}
]
];
$engine = new Mustache_Engine($options);
$rendered = $engine->render('{{#myFunc}}{{someVar}}{{/myFunction}}', ['someVar' => '12345']);
我該怎麼辦?