Meteor JS : How to pass parameters to helpers functions?

Make you function like that and you can call from html file.

'myFunction':function(param) {
    {...}
 }

Example

placePage.html

<template name="PlacePage">
     { ... }
     {{#each this.places}}
          <div class="input-group">
              Place name:
              {getPlaceName this._id}}
          </div>
     { ... }                             
</template>

placePage.js

Template.PlacePage.helpers({
    'getPlaceName':function(id) {
        if ( id === undefined || id.length < 1 ){
            return "";
        } else {
            var place = Places.findOne({_id:id});
            if ( place === undefined){
                return "";
            } else {
                return place.name ;
            }
        }
    }
});

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s