xp-forge / handlebars-templates

Handlebars templates for XP web frontends
1 stars 0 forks source link

Add helper functions extension #9

Closed thekid closed 2 years ago

thekid commented 2 years ago

PHP:

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:

thekid commented 2 years ago

Released in https://github.com/xp-forge/handlebars-templates/releases/tag/v1.1.0