How to pass multiple data context via template helpers?


#1

I have a form in my template to edit a product and I also load some categories from mongo to show in select options, when I access ‘this’ in my template events, it returns an empty object and this._id is undefined.

Template.editproduct.helpers({
     product() {
        const productId = Router.current().params._id;
        return Products.findOne({_id: productId});
    },
    categories() {
        return Categories.find({});
    }
});

How do would I be able to access a particular data context with ‘this’ in my events. And what’s the best way of passing multiple data context to a template?


#2

We need more information about your editproduct template to be able to provide you with solutions on what the context might look like.


#3

Confirm you’ve subscribed to Products and Categories.

In your template make sure categories list is wrapped in {{#each categories}} {{/each}}

And product stuff would be wrapped in a {{#with product}} {{/with}}

if that does not solve your issue we would need more info.


#4

Yeah, this was what I later did and it worked. Thanks