sreekar
sreekar

Reputation: 57

Meteor template helpers in coffeescript

I can't run any sort of computation (reactive or otherwise) inside of a template helper when using coffeescript, only return constant values.

if Meteor.isClient
    Template.fg.helpers(
        f: () -> [{val:1},{val:4},{val:9}] # works.
        g: () -> [{val: i*i} for i in [1..10]] # doesn't work.
    )

and the template

<template name="fg">
  {{#each f}} 
    <div>f: {{val}}</div>
  {{/each}} 
  {{#each g}} 
    <div>g: {{val}}</div>
  {{/each}} 
</template>

produces

f: 1
f: 4
f: 9
g:

But it works fine using javascript. Any suggestion on how to make g work?

Upvotes: 0

Views: 646

Answers (2)

Bhim Prasad Ale
Bhim Prasad Ale

Reputation: 523

Make following changes in your function g and it will work

Template.fg.helpers
f: () -> [{val:1},{val:4},{val:9}] # works.


g: () -> 
    for i in [1..10] # this also works
        val: i*i

It will give following out put

f: 1
f: 4
f: 9
g: 1
g: 4
g: 9
g: 16
g: 25
g: 36
g: 49
g: 64
g: 81
g: 100

Hope it will work :)

Upvotes: 0

mariomario
mariomario

Reputation: 660

I think this site could help.

So like this site mentions do something like this:

g: () -> (val: i*i for i in [0...10])

But I could be wrong, I an not really familiar with coffeescript or meteor.

Upvotes: 1

Related Questions