Search code examples
javascripthtmlmeteormeteor-blazemeteor-helper

Meteor not displaying information from collection in html


I am trying to get information from a collection in meteor and using a helper passing it to a template.

Here is my code on server.js:

Meteor.publish('dataForTableD1', function () {
    return Day1.find( { period: 1 } );
});

Here is my code on client.js:

Template.timetable.helpers({
    'day1p1': function() {
        Meteor.subscribe('dataForTableD1');
    }
});

Here is the template code:

{#with day1p1}}
    <td>{{lesson}}</td>
{{/with}}

The problem is that it won't display anything in the rendered page.

I am sure this is probably a typo or something similar on my part as I am quite new to meteor so any help would be appreciated.


Solution

  • You are just subscribing to dataForTableD1 but you don't return data in your day1p1 helper function. You probably want to use collection.findOne([selector], [options]) to return a document that matches a selector.

    Please try this:

    Template.timetable.helpers({
        'day1p1': function() {
            Meteor.subscribe('dataForTableD1');
            return Day1.findOne(); // add here your selector and options
        }
    });