mercredi 4 mars 2015

Handlebar helper syntax in Ember CLI

In this post


Handlebar js - iterating over for basic loop


An example of a 'repeat' helper is layed out.




helper



Handlebars.registerHelper('times', function(n, block) {
var accum = '';
for(var i = 0; i < n; ++i)
accum += block.fn(i);
return accum;
});




template



{{#times 10}}
<span>{{this}}</span>
{{/times}}


I can't seem to write this out the 'CLI' way... can someone enlighten me?


First of all, it will be it's own helper file in /helpers , and it should have a dash so the resolver recognizes it. - so I wouldn't be registering it explicitly.




Default generated helper looks like this helpers/repeat-times.js (template should be the same...)



import Ember from 'ember';

export function repeatTimes(input) {
return input;
}

export default Ember.Handlebars.makeBoundHelper(repeatTimes);




so, no need to register, no need to set the name... I just can't find clear docs on the syntax. :/ (I took 20 or so stabs at it...)


Or should I be making a component instead? as suggested here: Block helper with ember-cli





Aucun commentaire:

Enregistrer un commentaire