How to use helper functions in Meteor for render data

Posted By : Parveen Kumar Yadav | 14-Jul-2016

In meteor to render data you need to use helper functions.

So for defining helper just go to your template js file for example if you have a template name as allInventory so just go to allInventory.js file and write the helper as follows:-

Template.allInventory.helpers({

})
 

make a function inside this helper on which you put your logic for getting data from Database or Session or from other service and than use that in you html like:-


 Template.allInventory.helpers({
    productDetails: function() { 
          return Session.get('dbData');
    }
})
 

On html side you just need to use the function name as follows:-

 

{{#each productInfo in productDetails}}
      
        
{{productInfo.item_name}} {{productInfo.seller_sku}} {{productInfo.quantity}} {{productInfo.price}} {{/each}}

As you can see in above productDetails a function name in your helper class on which you get the data you want to render on your Html is accessible directly via that name and you can traverse that via each loop in html templates.

In this way you can render the data on html via use of helpers in Meteor.

Thanks

About Author

Author Image
Parveen Kumar Yadav

Parveen is an experienced Java Developer working on Java, J2EE, Spring, Hibernate, Grails ,Node.js,Meteor,Blaze, Neo4j, MongoDB, Wowza Streaming Server,FFMPEG,Video transcoding,Amazon web services, AngularJs, javascript. He likes to learn new technologies

Request for Proposal

Name is required

Comment is required

Sending message..