我想将变量传递给函数:
{{#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']);
我该怎么办?