PHP Moustache将变量传递给函数

时间:2017-02-16 22:51:27

标签: php mustache mustache.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']);

我该怎么办?

1 个答案:

答案 0 :(得分:-1)

你需要使用lambda,here你可以看到一个例子:

$data

该功能位于-pre-RA-sched