Dude
Dude

Reputation: 1045

assign :_id via route.js to use it in template.js - Meteor

I have 2 Collections:

Collection 1: Categories

Collection 2: Posts - with category_id so a Category have some Posts with the same category_id.

I have a template where I can see all my categories and I want now to click on a category to see its Posts where category_id is :_id.

route.js:

    this.route('postsList', {
    path: '/category/:_id',
    data: function() {
        return myCategories.findOne(this.params._id);
    }

now I know which category I have chosen but I have no clue how to get the _id in my template.js to do something like:

    Template.postsList.helpers({
        drinks: function(){
            return Posts.find({id:_id});
        }
});

The Problem is that I would like to get the :_id from my route into my template.js to work with it. this.params._id is not working for me in my template.js.

Upvotes: 0

Views: 42

Answers (1)

ajduke
ajduke

Reputation: 5057

You can pass the category id to your helper from html template.

You will need to pass the _id from your html to your helper function drinks

Something like this-

{{drinks _id}}

instead of just

{{drinks}}

Now, in helper get the id as parameter

drinks: function(id){
  // here you have the id passed from html, do whatever you want

}

Hope this helps.

Upvotes: 1

Related Questions