use web\frontend\{Frontend, Handlebars};
use web\frontend\extension\Functions;
$frontend= new Frontend($handler, new Handlebars($this->environment->path('src/main/handlebars'), [
new Functions([
'top' => fn($node, $context, $options) => array_slice($options[1], 0, $options[0])
])
]);
Handlebars:
{{#each (top 3 comments)}}
...
{{/each}}
The parameters to these helper functions are the following:
node: The current node, a com.github.mustache.Node instance
context: The current context, a com.github.mustache.Context instance
options: The resolved options passed, in the above example: [scalar(3), resolve(comments)]
PHP:
Handlebars:
The parameters to these helper functions are the following:
com.github.mustache.Node
instancecom.github.mustache.Context
instance[scalar(3), resolve(comments)]