Steering Assistant Syntax in Ember CLI

In this post

Iterate over a base for loop to use Handlebars.js

An example of the 'repeat' helper is issued.


assistant

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 "CLI" way ... can someone enlighten me?

First of all, it will be your own helper file in /helpers , and it must have a dash for the recognizer to recognize it. - therefore I would not register it explicitly.


The default helper looks like this: helpers/repeat-times.js (the template should be the same ...)

 import Ember from 'ember'; export function repeatTimes(input) { return input; } export default Ember.Handlebars.makeBoundHelper(repeatTimes); 


so there’s no need to register, no need to set a name ... I just can’t find clear documents on the syntax.: / (I took 20 or so hits) ...

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

+3
Mar 04 '15 at 21:30
source share
1 answer

@Kalman is right that you cannot register a related helper with the block record, so in this case I would recommend the component that was the link in the comment.

However, for those who could find this question and still want to create a handlebars helper in ember-cli, you will want to use the makeBoundHelper function.

For example, here is the current helper that I am using:

 // app/helpers/current-date.js import Ember from 'ember'; export default Ember.Handlebars.makeBoundHelper(function() { return moment().format('LL'); // Using moments format 'LL' }); 

Then in your handlebars template you can use this:

 {{current-date}} 

What the date gives, e.g. March 5, 2015

+4
Mar 05 '15 at 20:23
source share
β€” -



All Articles