0

In one of my helpers I have the following code

Template.App.onCreated(function() {
    this.settings = new ReactiveVar([]);
    Meteor.call('settings', (error, result) => {
        this.settings.set($.parseJSON(result));
    });
});

Template.App.helpers({
    data: function() {
        console.log(Template.instance().settings.get());
        return Template.instance().settings.get();
    }
});

It calls to a method that executes the following code

return Assets.getText('settings.default.json');

And in the console it would print

enter image description here

But when I try to use it in my template like this

{{#each data}}
    {{this.public.hello}}
    {{this.public.public.hello}}
{{/each}}

Neither works. No errors or anything anywhere. It displays nothing.

Why is this?

P. Nick
  • 955
  • 1
  • 12
  • 33
  • Your `data` function doesn't return anything. – baao Apr 07 '18 at 19:07
  • It's like baao says, you're returning the result from `Meteor.call`'s callback function, so that the data ends up inside the data function. You need to grab the data from the callback and then return it after `Meteor.call`'s semicolon. – LinusGeffarth Apr 07 '18 at 19:10
  • Thanks for the input. I defined a variable before the meteor call and assign the result to it, but when I return the variable after the meteor call the variable is undefined. – P. Nick Apr 07 '18 at 19:15
  • Can you show that code? Is the callback async? Like, is the variable even being written to before returning from `data`? – LinusGeffarth Apr 07 '18 at 19:22
  • Your edited code looks like to should work. Try with explicit data context aka {{# each foo in bar}} {{foo.baz}} {{/each}} – coagmano Apr 09 '18 at 05:17

0 Answers0